// JavaScript Document
function checkTheBox()
{
	if(document.getElementById('hdes_name').value=='')
	{
		alert('Please Select the Soldering 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;  
	}
	if(document.getElementById('st_tim').value=='')
	{
		alert('Please enter the Finishing Time');  
		document.getElementById('st_tim').focus();
		return false; 
	}
	
	var chk = document.getElementsByName('category[]');
    var len = chk.length;
	//alert(len);
	var flag = 0;
	if(len==1)
	{
		if(document.checklist["category[]"].checked)
		{
			var letters=/^\d+(?:\.\d+)?$/;
			var letters1=/^\d+$/;
			if(document.getElementById('no_mas1').value=='')
			{
				alert('Please Enter No of Master');  
				document.getElementById('no_mas1').focus();  
				return false; 
			}
			else if(letters1.test(document.getElementById('no_mas1').value)==false)  
			{
				alert('No of Master Should have only Integers');  
				document.getElementById('no_mas1').focus();  
				return false;  
			}
			if(document.getElementById('sil_wt1').value=='')
			{
				alert('Please Enter Silver Weight');  
				document.getElementById('sil_wt1').focus();  
				return false; 
			}
			else if(letters.test(document.getElementById('sil_wt1').value)==false)  
			{
				alert('Silver Weight Should have only Decimal');  
				document.getElementById('sil_wt1').focus();  
				return false;  
			}
			if(document.getElementById('run_wt1').value=='')
			{
				alert('Please Enter Runner Weight');  
				document.getElementById('run_wt1').focus();  
				return false; 
			}
			else if(letters.test(document.getElementById('run_wt1').value)==false)  
			{
				alert('Runner Weight Should have only Decimal');  
				document.getElementById('run_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+)?$/;
			var letters1=/^\d+$/;
			if(document.getElementById('no_mas'+j).value=='')
			{
				alert('Please Enter No of Master');  
				document.getElementById('no_mas'+j).focus();  
				return false; 
			}
			else if(letters1.test(document.getElementById('no_mas'+j).value)==false)  
			{
				alert('No of Master Should have only Integers');  
				document.getElementById('no_mas'+j).focus();  
				return false;  
			}
			if(document.getElementById('sil_wt'+j).value=='')
			{
				alert('Please Enter Silver Weight for Design '+j);  
				document.getElementById('sil_wt'+j).focus();  
				return false; 
			}
			else if(letters.test(document.getElementById('sil_wt'+j).value)==false)  
			{
				alert('Silver Weight Should have only Decimal for Design '+j);  
				document.getElementById('sil_wt'+j).focus();  
				return false;  
			}
			
			if(document.getElementById('run_wt'+j).value=='')
			{
				alert('Please Enter Runner Weight for Design '+j);  
				document.getElementById('run_wt'+j).focus();  
				return false; 
			}
			else if(letters.test(document.getElementById('run_wt'+j).value)==false)  
			{
				alert('Runner Weight Should have only Decimal for Design '+j);  
				document.getElementById('run_wt'+j).focus();  
				return false;  
			}
			
			flag ++;
			
		}
	}
	}
	
	if (flag <1)
	{
		alert ("Please Select the items");
		return false;
	}
	else
	{	
		var letters=/^\d+(?:\.\d+)?$/;
		if(document.getElementById('kdm_wgt').value=='')
		{
			alert('Please Enter the KDM Weight');  
			document.getElementById('kdm_wgt').focus();  
			return false; 
		}
		else if(letters.test(document.getElementById('kdm_wgt').value)==false)  
		{
			alert('KDM Weight Should have only Decimal Value '+j);  
			document.getElementById('kdm_wgt').focus();  
			return false;  
		}
		/*if(document.getElementById('dust_wgt').value=='')
		{
			alert('Please Enter the Dust Weight');  
			document.getElementById('dust_wgt').focus();  
			return false; 
		}
		else*/
		if(document.getElementById('dust_wgt').value!='')
		{
			if(letters.test(document.getElementById('dust_wgt').value)==false)  
			{
				alert('Dust Weight Should have only Decimal Value ');  
				document.getElementById('dust_wgt').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!='' && document.getElementById('lob').value!='')
	{		
		var des_id = document.getElementById('hdes_name').value;
		var dat = encodeURIComponent(document.getElementById('lob').value);	
		window.location = 'sol_finishing_add.php?des_name='+des_id+'&dat='+dat;
	}
	/*else
	{
		if(document.getElementById('hdes_name').value=="")
		{
			alert('Please select the Worker Name');  
			document.getElementById('hdes_name').focus();  
			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 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;  
			}
		}
	}*/
	
}
function wastge_cal(ids,loop)
{
	var sol = parseFloat(document.getElementById('sol_wt'+loop).value.trim());
	var sil = parseFloat(document.getElementById('sil_wt'+loop).value.trim());
	var run = parseFloat(document.getElementById('tot_wt'+loop).value.trim());
	
	if(sil!='')
	{
		if(sil>sol)
		{
			alert("Finishing Weight not greater than Loading Weight");
			document.getElementById('sil_wt'+loop).value="";
			document.getElementById('wst_wt'+loop).value = "0.00";	
			document.getElementById('wastg'+loop).innerHTML="0.00 g";
			document.getElementById('run_wt'+loop).value = "0.00";		
			document.getElementById('tot_wgt'+loop).innerHTML="0.00 g";
			return false;
			
		}
		else if(sil<=sol)
		{
			document.getElementById('wst_wt'+loop).value = (sol-sil).toFixed(2);	
			document.getElementById('wastg'+loop).innerHTML=(sol-sil).toFixed(2);
		}
	}
	else
	{
		document.getElementById('wst_wt'+loop).value = "0.00";	
		document.getElementById('wastg'+loop).innerHTML="0.00 g";
		document.getElementById('run_wt'+loop).value = "0.00";		
		document.getElementById('tot_wgt'+loop).innerHTML="0.00 g";
	}
	
	if(sil!='' && run!='')
	{
		if(sil<run)
		{
			document.getElementById('run_wt'+loop).value=(run-sil).toFixed(2);		
			document.getElementById('tot_wgt'+loop).innerHTML=(run-sil).toFixed(2);
		}
		else if(sil>run)
		{
			alert("Total Weight must greater than Silver Weight");
			document.getElementById('wst_wt'+loop).value = "0.00";	
			document.getElementById('wastg'+loop).innerHTML="0.00 g";
			document.getElementById('run_wt'+loop).value = "0.00";		
			document.getElementById('tot_wgt'+loop).innerHTML="0.00 g";
			return false;
		}
	}
	else
	{
		document.getElementById('run_wt'+loop).value = "0.00";		
		document.getElementById('tot_wgt'+loop).innerHTML="0.00 g";
	}
	
	
}
