// JavaScript Document

var catChecked = false;

function check_ajax(ids)
{
	if (catChecked) return; // ❗ prevent repeated checking
	//alert(ids);
	document.getElementById("lod").innerHTML = '<img src="images/elements/loaders/loader.gif" />'
	//var ids = document.getElementById("cat_name").value;
	if (window.XMLHttpRequest)
	{
		// code for IE7+, Firefox, Chrome, Opera, Safari
		xmlhttp=new XMLHttpRequest();
	}
	else
	{
		// code for IE6, IE5
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	xmlhttp.onreadystatechange=function()
	{
		if (xmlhttp.readyState==4 && xmlhttp.status==200)
		{
			var res = xmlhttp.responseText;
			//alert(res);
			if(res.trim()=="yes")
			{
				 catChecked = true;  // prevent infinite loop
				alert("This Employee Name is already Exist");	
				document.getElementById("lod").innerHTML ='';
				document.getElementById("e_name").value ='';
				document.getElementById("e_name").focus();
				return false;
			}
			else
			{
				document.getElementById("lod").innerHTML ='';
			}
		}
	}
	
	var qurl ="?ajax_id=1&vals=" + ids
	//alert(qurl);
	xmlhttp.open("GET","ajax/emp_ajax.php"+qurl,true);
	xmlhttp.send();	
}// JavaScript Document
//dept_name,e_name,dob,e_id,mob,add,resume,bg,mob1.mob2,remak,of_add,co_add,
function redir_pg(party_id,cat_id)
{
	//window.location='party_cost_log_list.php?party_id='+party_id+'&cate_id='+cat_id;
	$("#main_div").load("emp_cad_log_list.php?emp_id="+party_id+"&cate_id="+cat_id,function(response)
	{});
}
function fom_validate()
{
	if(document.getElementById('dept_name').value=='')
	{
		alert('Please Select the Department');  
		window.scrollTo(10,20);
		document.getElementById('dept_name').focus();  
		return false; 
	}
	
	var letters=/^[A-Za-z][A-Za-z. ]+$/; 
	if(document.getElementById('e_name').value=='')
	{
		alert('Please Enter the Employee Name');  
		document.getElementById('e_name').focus();  
		return false; 
	}
	else if(letters.test(document.getElementById('e_name').value)==false)  
	{
		alert('Employee Name must have Alphanumeric only');  
		document.getElementById('e_name').focus();  
		return false;  
	}
	
	var letters=/^(0?[1-9]|[12][0-9]|3[01])[\/\-](0?[1-9]|1[012])[\/\-]\d{4}$/;
	if(document.getElementById('dob').value=='')
	{
		alert('Please Enter the Employee D O B');  
		document.getElementById('dob').focus();  
		return false; 
	}
	else if(letters.test(document.getElementById('dob').value)==false)  
	{
		alert('Employee D O B must be in the given Format');  
		document.getElementById('dob').focus();  
		return false;  
	}
	
	var letters = /^[0-9]{10}$/;  
	if(document.getElementById('mob1').value=='')
	{
		alert('Please Enter the Phone No 1');  
		document.getElementById('mob1').focus();  
		return false; 
	}
	else if(letters.test(document.getElementById('mob1').value)==false)  
	{
		alert('Phone Number 1 must have numeric and exactly 10 digits');  
		document.getElementById('mob1').focus();  
		return false;  
	}
	
	var letters = /^[0-9]{10}$/;  
	if(document.getElementById('mob2').value!='')
	{
		/*alert('Please Enter the Phone No');  
		document.getElementById('mob2').focus();  
		return false; */
		if(letters.test(document.getElementById('mob2').value)==false)  
		{
			alert('Phone Number 2 must have numeric and exactly 10 digits');  
			document.getElementById('mob2').focus();  
			return false;  
		}
	}
	
	var letters=/^[A-Za-z][A-Za-z. ]+$/; 
	if(document.getElementById('per_nm').value=='')
	{
		alert('Please Enter the Contact Person Name');  
		document.getElementById('per_nm').focus();  
		return false; 
	}
	else if(letters.test(document.getElementById('per_nm').value)==false)  
	{
		alert('Contact Person Name must have Alphabets only');  
		document.getElementById('per_nm').focus();  
		return false;  
	}
	
	var letters = /^[0-9]{10}$/;  
	if(document.getElementById('mob3').value=='')
	{
		alert('Please Enter the Contact Person Phone No');  
		document.getElementById('mob3').focus();  
		return false; 
	}
	else if(letters.test(document.getElementById('mob1').value)==false)  
	{
		alert('Contact Person Phone Number must have numeric and exactly 10 digits');  
		document.getElementById('mob3').focus();  
		return false;  
	}
	
	var letters=/^[A-Za-z][A-Za-z. ]+$/; 
	if(document.getElementById('relan').value=='')
	{
		alert('Please Enter the Relationship');  
		document.getElementById('relan').focus();  
		return false; 
	}
	else if(letters.test(document.getElementById('relan').value)==false)  
	{
		alert('Relationship must have Alphabets only');  
		document.getElementById('relan').focus();  
		return false;  
	}
	
	var letters = /^[a-zA-Z0-9][a-zA-Z0-9_.-]+@[a-zA-Z_]+?\.[a-zA-Z]{2,3}$/; 
	if(document.getElementById('e_id').value!='')    
	{
		/*alert('Please Enter the Email ID 1');  
		document.getElementById('e_id').focus();  
		return false;*/
		if(letters.test(document.getElementById('e_id').value)==false)  
		{
			alert('Email ID is  not valid');  
			document.getElementById('e_id').focus();  
			return false;  
		} 
	}
	
	/*if(document.getElementById('add').value!='')
	{
		var addr = document.getElementById('add').value;
		var len = addr.length;
		if(len < 10)
		{
			alert('Address Should be Greater than 10 Letters');  
			document.getElementById('add').focus();  
			return false;
		}
	}*/
	var letters_add2 = /^[\s]+$/; 
	if(document.getElementById('of_add').value=='')
	{
		alert('Please Enter the Perminant Address');  
		document.getElementById('of_add').focus();  
		return false;
	}
	else if(document.getElementById('of_add').value!='')
	{
		var addr = document.getElementById('of_add').value;
		var len = addr.length;
		if(letters_add2.test(document.getElementById('of_add').value)==true)  
		{
			alert("Perminant Address Can't Start with Spaces");  
			document.getElementById('of_add').focus();  
			return false;  
		}
		else if(len < 10)
		{
			alert('Perminant Address Should be Greater than 10 Letters');  
			document.getElementById('of_add').focus();  
			return false;
		}
	}
	
	var letters_add2 = /^[\s]+$/; 
	if(document.getElementById('co_add').value=='')
	{
		alert('Please Enter the Recidential Address');  
		document.getElementById('co_add').focus();  
		return false;
	}
	else if(document.getElementById('co_add').value!='')
	{
		var addr = document.getElementById('co_add').value;
		var len = addr.length;
		if(letters_add2.test(document.getElementById('co_add').value)==true)  
		{
			alert("Recidential Address Can't Start with Spaces");  
			document.getElementById('co_add').focus();  
			return false;  
		}
		else if(len < 10)
		{
			alert('Recidential Address Should be Greater than 10 Letters');  
			document.getElementById('co_add').focus();  
			return false;
		}
	}
	
	if(document.getElementById('resume').value!='')
	{
		var emp_phto=document.getElementById('resume').value; 			
		var b = document.getElementById('resume');
		var f = -1;		
		var oas;
		var filesize = b.files[0].size; // b.files[0].Size;
		var size1=filesize / (1024 * 1024);
		//alert(size1 + " MB");
		if (size1 > 1.0) 
		{
			alert('Please check the Employee Resume size[File Size Minimum 1MB]');
			return false;
			// return true;
		}
		var ext = emp_phto.substring(emp_phto.lastIndexOf('.') + 1);
		//alert(ext);
		if(ext!="doc" && ext !="DOC" && ext!="docx" && ext!="DOCX" && ext !="PDF" && ext!="pdf" && ext !="XLS" && ext!="xls" && ext !="XLSX" && ext!="xlsx")
		{
			alert('Browse only .doc,.docx,.pdf file for Employee Resume');    
			document.getElementById('resume').focus();  
			return false;
		}
		
	}
	
	//fmd, tod, sal_amt,rem
	var letters=/^(0?[1-9]|[12][0-9]|3[01])[\/\-](0?[1-9]|1[012])[\/\-]\d{4}$/;
	if(document.getElementById('fmd').value!='')
	{
		/*alert('Please Enter the Employee D O B');  
		document.getElementById('dob').focus();  
		return false; */
		
		if(letters.test(document.getElementById('fmd').value)==false)  
		{
			alert('From Date must be in the given Format');  
			document.getElementById('fmd').focus();  
			return false;  
		}
	}
	
	var letters=/^(0?[1-9]|[12][0-9]|3[01])[\/\-](0?[1-9]|1[012])[\/\-]\d{4}$/;
	if(document.getElementById('tod').value!='')
	{
		/*alert('Please Enter the Employee D O B');  
		document.getElementById('dob').focus();  
		return false; */
		
		if(letters.test(document.getElementById('tod').value)==false)  
		{
			alert('To Date must be in the given Format');  
			document.getElementById('tod').focus();  
			return false;  
		}
	}
	
	if(document.getElementById('fmd').value!='' && document.getElementById('tod').value!='')
	{
		if(document.getElementById('sal_amt').value=='')
		{
			alert('Please Enter the Salary');  
			document.getElementById('sal_amt').focus();  
			return false;
		}		
	}
	
	var letters=/^\d+(?:\.\d+)?$/;
	if(document.getElementById('sal_amt').value!='')
	{
		if(letters.test(document.getElementById('sal_amt').value)==false)  
		{
			alert('Salary Should have only Digits');  
			document.getElementById('sal_amt').focus();  
			return false;  
		}
	}
	
	var where_to= confirm("Do you really want to Submit the Data?");
	if (where_to== true)
	{
		document.fm.submit();
	}
	else
	{
		return false;	
	}
}
function fom_validate_upd()
{
	if(document.getElementById('dept_name').value=='')
	{
		alert('Please Select the Department');  
		window.scrollTo(10,20);
		document.getElementById('dept_name').focus();  
		return false; 
	}
	
	var letters=/^[A-Za-z][A-Za-z. ]+$/; 
	if(document.getElementById('e_name').value=='')
	{
		alert('Please Enter the Employee Name');  
		document.getElementById('e_name').focus();  
		return false; 
	}
	else if(letters.test(document.getElementById('e_name').value)==false)  
	{
		alert('Employee Name must have Alphanumeric only');  
		document.getElementById('e_name').focus();  
		return false;  
	}
	
	var letters=/^(0?[1-9]|[12][0-9]|3[01])[\/\-](0?[1-9]|1[012])[\/\-]\d{4}$/;
	if(document.getElementById('dob').value=='')
	{
		alert('Please Enter the Employee D O B');  
		document.getElementById('dob').focus();  
		return false; 
	}
	else if(letters.test(document.getElementById('dob').value)==false)  
	{
		alert('Employee D O B must be in the given Format');  
		document.getElementById('dob').focus();  
		return false;  
	}
	
	var letters = /^[0-9]{10}$/;  
	if(document.getElementById('mob1').value=='')
	{
		alert('Please Enter the Phone No 1');  
		document.getElementById('mob1').focus();  
		return false; 
	}
	else if(letters.test(document.getElementById('mob1').value)==false)  
	{
		alert('Phone Number 1 must have numeric and exactly 10 digits');  
		document.getElementById('mob1').focus();  
		return false;  
	}
	
	var letters = /^[0-9]{10}$/;  
	if(document.getElementById('mob2').value!='')
	{
		if(letters.test(document.getElementById('mob2').value)==false)  
		{
			alert('Phone Number 2 must have numeric and exactly 10 digits');  
			document.getElementById('mob2').focus();  
			return false;  
		}
	}
	
	var letters=/^[A-Za-z][A-Za-z. ]+$/; 
	if(document.getElementById('per_nm').value=='')
	{
		alert('Please Enter the Contact Person Name');  
		document.getElementById('per_nm').focus();  
		return false; 
	}
	else if(letters.test(document.getElementById('per_nm').value)==false)  
	{
		alert('Contact Person Name must have Alphabets only');  
		document.getElementById('per_nm').focus();  
		return false;  
	}
	
	var letters = /^[0-9]{10}$/;  
	if(document.getElementById('mob3').value=='')
	{
		alert('Please Enter the Contact Person Phone No');  
		document.getElementById('mob3').focus();  
		return false; 
	}
	else if(letters.test(document.getElementById('mob1').value)==false)  
	{
		alert('Contact Person Phone Number must have numeric and exactly 10 digits');  
		document.getElementById('mob3').focus();  
		return false;  
	}
	
	var letters=/^[A-Za-z][A-Za-z. ]+$/; 
	if(document.getElementById('relan').value=='')
	{
		alert('Please Enter the Relationship');  
		document.getElementById('relan').focus();  
		return false; 
	}
	else if(letters.test(document.getElementById('relan').value)==false)  
	{
		alert('Relationship must have Alphabets only');  
		document.getElementById('relan').focus();  
		return false;  
	}
	
	var letters = /^[a-zA-Z0-9][a-zA-Z0-9_.-]+@[a-zA-Z_]+?\.[a-zA-Z]{2,3}$/; 
	if(document.getElementById('e_id').value!='')    
	{
		if(letters.test(document.getElementById('e_id').value)==false)  
		{
			alert('Email ID is  not valid');  
			document.getElementById('e_id').focus();  
			return false;  
		} 
	}
	
	var letters_add2 = /^[\s]+$/; 
	if(document.getElementById('of_add').value=='')
	{
		alert('Please Enter the Perminant Address');  
		document.getElementById('of_add').focus();  
		return false;
	}
	else if(document.getElementById('of_add').value!='')
	{
		var addr = document.getElementById('of_add').value;
		var len = addr.length;
		if(letters_add2.test(document.getElementById('of_add').value)==true)  
		{
			alert("Perminant Address Can't Start with Spaces");  
			document.getElementById('of_add').focus();  
			return false;  
		}
		else if(len < 10)
		{
			alert('Perminant Address Should be Greater than 10 Letters');  
			document.getElementById('of_add').focus();  
			return false;
		}
	}
	
	var letters_add2 = /^[\s]+$/; 
	if(document.getElementById('co_add').value=='')
	{
		alert('Please Enter the Recidential Address');  
		document.getElementById('co_add').focus();  
		return false;
	}
	else if(document.getElementById('co_add').value!='')
	{
		var addr = document.getElementById('co_add').value;
		var len = addr.length;
		if(letters_add2.test(document.getElementById('co_add').value)==true)  
		{
			alert("Recidential Address Can't Start with Spaces");  
			document.getElementById('co_add').focus();  
			return false;  
		}
		else if(len < 10)
		{
			alert('Recidential Address Should be Greater than 10 Letters');  
			document.getElementById('co_add').focus();  
			return false;
		}
	}
	
	if(document.getElementById('resume').value!='')
	{
		var emp_phto=document.getElementById('resume').value; 			
		var b = document.getElementById('resume');
		var f = -1;		
		var oas;
		var filesize = b.files[0].size; // b.files[0].Size;
		var size1=filesize / (1024 * 1024);
		//alert(size1 + " MB");
		if (size1 > 1.0) 
		{
			alert('Please check the Employee Resume size[File Size Minimum 1MB]');
			return false;
			// return true;
		}
		var ext = emp_phto.substring(emp_phto.lastIndexOf('.') + 1);
		//alert(ext);
		if(ext!="doc" && ext !="DOC" && ext!="docx" && ext!="DOCX" && ext !="PDF" && ext!="pdf" && ext !="XLS" && ext!="xls" && ext !="XLSX" && ext!="xlsx")
		{
			alert('Browse only .doc,.docx,.pdf file for Employee Resume');    
			document.getElementById('resume').focus();  
			return false;
		}
		
	}
	
	var sal_loop = document.getElementById('sal_loop').value;
	if(sal_loop!=0)
	{
		for(var i=1;i<sal_loop;i++)
		{
			var letters=/^(0?[1-9]|[12][0-9]|3[01])[\/\-](0?[1-9]|1[012])[\/\-]\d{4}$/;
			if(document.getElementById('fmd_'+i).value!='')
			{
				if(letters.test(document.getElementById('fmd_'+i).value)==false)  
				{
					alert('From Date must be in the given Format');  
					document.getElementById('fmd_'+i).focus();  
					return false;  
				}
			}
			
			var letters=/^(0?[1-9]|[12][0-9]|3[01])[\/\-](0?[1-9]|1[012])[\/\-]\d{4}$/;
			if(document.getElementById('tod_'+i).value!='')
			{
				if(letters.test(document.getElementById('tod_'+i).value)==false)  
				{
					alert('To Date must be in the given Format');  
					document.getElementById('tod_'+i).focus();  
					return false;  
				}
			}
			
			if(document.getElementById('fmd_'+i).value!='' && document.getElementById('tod_'+i).value!='')
			{
				if(document.getElementById('sal_amt_'+i).value=='')
				{
					alert('Please Enter the Salary');  
					document.getElementById('sal_amt_'+i).focus();  
					return false;
				}		
			}
			
			var letters=/^\d+(?:\.\d+)?$/;
			if(document.getElementById('sal_amt_'+i).value!='')
			{
				if(letters.test(document.getElementById('sal_amt_'+i).value)==false)  
				{
					alert('Salary Should have only Digits');  
					document.getElementById('sal_amt_'+i).focus();  
					return false;  
				}
			}
		}
	}
	var num_flagg = document.getElementById('num_flagg').value;
	if(num_flagg==1)
	{
		//fmd, tod, sal_amt,rem
		var letters=/^(0?[1-9]|[12][0-9]|3[01])[\/\-](0?[1-9]|1[012])[\/\-]\d{4}$/;
		if(document.getElementById('fmd').value!='')
		{
			if(letters.test(document.getElementById('fmd').value)==false)  
			{
				alert('From Date must be in the given Format');  
				document.getElementById('fmd').focus();  
				return false;  
			}
		}
		
		var letters=/^(0?[1-9]|[12][0-9]|3[01])[\/\-](0?[1-9]|1[012])[\/\-]\d{4}$/;
		if(document.getElementById('tod').value!='')
		{
			if(letters.test(document.getElementById('tod').value)==false)  
			{
				alert('To Date must be in the given Format');  
				document.getElementById('tod').focus();  
				return false;  
			}
		}
		
		if(document.getElementById('fmd').value!='' && document.getElementById('tod').value!='')
		{
			if(document.getElementById('sal_amt').value=='')
			{
				alert('Please Enter the Salary');  
				document.getElementById('sal_amt').focus();  
				return false;
			}		
		}
		
		var letters=/^\d+(?:\.\d+)?$/;
		if(document.getElementById('sal_amt').value!='')
		{
			if(letters.test(document.getElementById('sal_amt').value)==false)  
			{
				alert('Salary Should have only Digits');  
				document.getElementById('sal_amt').focus();  
				return false;  
			}
		}
	}
	
	
	var where_to= confirm("Do you really want to Submit the Data?");
	if (where_to== true)
	{
		document.fm.submit();
	}
	else
	{
		return false;	
	}
}
/*function enable_file(idss)
{
	ids=idss+1;
	document.getElementById('span_plu'+idss).style.display='none';
	document.getElementById('file_div'+ids).style.display='block';
	document.getElementById('span_min'+idss).style.display='none';
	document.getElementById('file_limit').value=ids;
	
}
function disable_file(ids)
{
	document.getElementById('file_div'+ids).style.display='none';
	idss=ids-1;
	if(idss!=1)
	{
		document.getElementById('span_plu'+idss).style.display='block';
		document.getElementById('span_min'+idss).style.display='block';
	}
	else 
	{
		document.getElementById('span_plu'+idss).style.display='block';
	}
	document.getElementById('file_limit').value=idss;
	
	
}*/

function copy_addr()
{
	document.getElementById('co_add').value = '';
	var addr = document.getElementById('of_add').value;  	
	document.getElementById('co_add').value = addr;
}

function form_rest() //this is for reset the forms
{
	var where_to= confirm("Do you really want to Reset the Data?");
	if (where_to== true)
	{
		window.location.reload();
	}
	else
	{
	 	return false;	
	}
}


function foc(ids)
{
	//alert(ids+"_div");
	document.getElementById(ids+"_div").style.border="2px solid #0099FF";	
}

function stnon(ids)
{
	//alert(ids+"_div");
	document.getElementById(ids+"_div").style.border="thin solid #EEFFFF";
}