// JavaScript Document
function checkTheBox()
{
	if(document.getElementById('hdes_name').value=='')
	{
		alert('Please Select the Buffing Worker Name');  
		document.getElementById('hdes_name').focus();
		window.scrollTo(10,10);  
		return false; 
	}
	
	var letters=/^(0?[1-9]|[12][0-9]|3[01])[\/\-](0?[1-9]|1[012])[\/\-]\d{4}$/;
	if(document.getElementById('lob').value=='')
	{
		alert('Please Enter Finishing Date');  
		document.getElementById('lob').focus();  
		return false; 
	}
	else if(letters.test(document.getElementById('lob').value)==false)  
	{
		alert('Finishing Date must be in the given Format');  
		document.getElementById('lob').focus();  
		return false;  
	}
	
	var chk = document.getElementsByName('category[]');
    var len = chk.length;
	var flag = 0;
	if(len==1)
	{
		if(document.checklist["category[]"].checked)
		{
			var letters=/^\d+(?:\.\d+)?$/;
			if(document.getElementById('fin_wt1').value=='')
			{
				alert('Please Enter Finish Weight');  
				document.getElementById('fin_wt1').focus();  
				return false; 
			}
			else if(letters.test(document.getElementById('fin_wt1').value)==false)  
			{
				alert('Finish Weight Should have only Decimal');  
				document.getElementById('fin_wt1').focus();  
				return false;  
			}
			
			flag++;
			
		}
		else
		{
			flag=0;
		}
	}
	else
	{
		for (var i = 0; i < len; i++)
		{
			if(document.checklist["category[]"][i].checked)
			{
				var j=i+1;
				var letters=/^\d+(?:\.\d+)?$/;
				if(document.getElementById('fin_wt'+j).value=='')
				{
					alert('Please Enter Finish Weight for Design '+j);  
					document.getElementById('fin_wt'+j).focus();  
					return false; 
				}
				else if(letters.test(document.getElementById('fin_wt'+j).value)==false)  
				{
					alert('Finish Weight Should have only Decimal for Design '+j);  
					document.getElementById('fin_wt'+j).focus();  
					return false;  
				}
				
				flag ++;
				
			}
		}
	}
	
	var chk = document.getElementsByName('category[]');
    var len = chk.length;
	//alert(len);
	var flag = 0;
	if(len==1)
	{
		if(document.checklist["category[]"].checked)
		{
			flag++;
		}
		else
		{
			flag=0;
		}
	}
	else
	{
	for (var i = 0; i< len; i++)
	{
		if(document.checklist["category[]"][i].checked)
		{
			flag ++;
		}
	}
	}
	if (flag <1)
	{
		alert ("Please Select the items");
		return false;
	}
	else
	{
	
	/*if ( ( checklist.question1[0].checked == false ) && ( checklist.question1[1].checked == false ) ) 
	{
		alert ("Please Select the Next Process Cam OR RTV");
		checklist.question1[0].focus();  
		return false;
	}*/
	
	 var item1="";
	if(flag==1)
	{
		item1="Item";
	}
	else
	{
		item1="Items";
	}
	 var where_to= confirm("You Have Selected "+ flag +" "+item1+"\n Do you really want to Submit the selected items?");
	 if (where_to== true)
	 {
		 document.checklist.submit();			 
	   
	 }
	 else
	 {
		 return false;
	  
	 }
	}
}
	

function checkTheBox1()
{
	var chk = document.getElementsByName('category[]');
    var len = chk.length;
	var flag = 0;
	if(len==1)
	{
		if(document.checklist["category[]"].checked)
		{
			flag++;
		}
		else
		{
			flag=0;
		}
	}
	else
	{
	for (var i = 0; i< len; i++)
	{
		if(document.checklist["category[]"][i].checked)
		{
			flag ++;
		}
	}
	}
	if (flag <1)
	{
		alert ("Please Select the items");
		return false;
	}
	return true;
		
}


function fom_validate()
{
	
	var where_to= confirm("Do you really want to Submit the Data?");
	if (where_to== true)
	{
		document.checklist.submit();
	}
	else
	{
		return false;	
	}
}

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)
{
	document.getElementById(ids).style.border="2px solid #0099FF";
	
}

function stnon(ids)
{
	document.getElementById(ids).style.border="thin solid #CCCCCC";
}

function reload_page() //this is for reloadin the page when selecting the comapny code
{
	if(document.getElementById('hdes_name').value!="")
	{
		var des_id = document.getElementById('hdes_name').value;	
	}
	else
	{
		var des_id = '';
	}	
	
	var letters=/^(0?[1-9]|[12][0-9]|3[01])[\/](0?[1-9]|1[012])[\/]\d{4}$/;
	if(document.getElementById('lob').value=='')
	{
		alert('Please Enter the Finishing Date');  
		document.getElementById('lob').focus();  
		return false; 
	}
	else 
	{
		if(letters.test(document.getElementById('lob').value)==false)  
		{
			alert('Finishing Date must be in the given Format');  
			document.getElementById('lob').focus();  
			return false;  
		}
		else
		{	
			var dat = encodeURIComponent(document.getElementById('lob').value);	
			window.location = 'buf_finishing_add.php?des_name='+ des_id +"&dat=" + dat;
		}
	}
	
}
function wastge_cal(ids,loop)
{
	var lod_wt = parseFloat(document.getElementById('lod_wt'+loop).value);
	var fin_wt = parseFloat(document.getElementById('fin_wt'+loop).value);
	
	if(fin_wt!='')
	{
		if(fin_wt>lod_wt)
		{
			alert("Finishing Weight not greater than Loading Weight");
			document.getElementById('fin_wt'+loop).value="";
			document.getElementById('wst_wt'+loop).value = "0.00";	
			document.getElementById('wastg'+loop).innerHTML="0.00 g";
			return false;
			
		}
		else if(fin_wt<=lod_wt)
		{
			document.getElementById('wst_wt'+loop).value = (lod_wt-fin_wt).toFixed(2);	
			document.getElementById('wastg'+loop).innerHTML=(lod_wt-fin_wt).toFixed(2)+" g";
		}		
	}
	else
	{
		document.getElementById('wst_wt'+loop).value = "0.00";	
		document.getElementById('wastg'+loop).innerHTML="0.00 g";
	}
}

