// JavaScript Document
function dynamic_tabel_add(id_val)
{
	var count_val=document.getElementById("count_div").value;
	var idss=id_val.split(",");
	ids=idss[1];
	ids=parseInt(ids);
	if(ids==0)
	{
		var lpp = document.getElementById("cur_count2").value;
		if(lpp>1)
		{
			for(i=lpp;i<=count_val-1;i++)
			{
				document.getElementById("stone_div"+i).style.display='none';
			}
			if((lpp-1)==1)
			{
				var lop = lpp-1;
				document.getElementById("remov_sm,"+lop).style.display='none';
			}
			else if((lpp-1)>1)
			{			
				for(lop=1;lop<lpp-1;lop++)
				{
					document.getElementById("remov_sm,"+lop).style.display='none';
					document.getElementById("plus_sm,"+lop).style.display='none';
				}
			}
		}
		else
		{
			for(i=2;i<=count_val-1;i++)
			{
				document.getElementById("stone_div"+i).style.display='none';
			}
			document.getElementById("remov_sm,1").style.display='none';
		}
	}
	else
	{		
		var next_id=ids+1;
		count_val=count_val-1;
		if(next_id!=count_val)
		{
			document.getElementById("plus_sm,"+ids).style.display='none';
			document.getElementById("remov_sm,"+ids).style.display='none';
			document.getElementById("stone_div"+next_id).style.display='block';
		}
		else
		{
			document.getElementById("plus_sm,"+ids).style.display='none';
			document.getElementById("remov_sm,"+ids).style.display='none';
			document.getElementById("plus_sm,"+next_id).style.display='none';
			document.getElementById("remov_sm,"+next_id).style.display='block';
			document.getElementById("stone_div"+next_id).style.display='block';
		}
			document.getElementById("cur_count").value=next_id;	
	}	
}

function dynamic_tabel_remove(id_val,suppl_nm)
{
	var idss=id_val.split(",");
	ids=idss[1];
	ids=parseInt(ids);
	var pre_id=ids-1;
	if(pre_id==1)
	{
		if(suppl_nm=="")
		{
			document.getElementById("plus_sm,"+pre_id).style.display='block';
			document.getElementById("remov_sm,"+pre_id).style.display='none';
			document.getElementById("stone_div"+ids).style.display='none';
		}
		else
		{	
			if(document.getElementById('cat_name'+ids).value!="" || document.getElementById('stn_size'+ids).value!="" || document.getElementById('stn_wght'+ids).value!="" || document.getElementById('quanty'+ids).value!="" || document.getElementById('tot_wght'+ids).value!="") 
			{	
				var c_var=confirm("Are you Sure Want to Remove this Row?");
				if(c_var==true)
				{
					document.getElementById('cat_name'+ids).value="";
					document.getElementById('stn_size'+ids).value="";
					document.getElementById('stn_wght'+ids).value="";
					document.getElementById('quanty'+ids).value="";
					document.getElementById('tot_wght'+ids).value="0.0000";
					document.getElementById("plus_sm,"+pre_id).style.display='block';
					document.getElementById("remov_sm,"+pre_id).style.display='none';
					document.getElementById("stone_div"+ids).style.display='none';
					tot_price_cal();
				}
				else
				{
					return false;
				}
			}
			else
			{
				document.getElementById("plus_sm,"+pre_id).style.display='block';
				document.getElementById("remov_sm,"+pre_id).style.display='none';
				document.getElementById("stone_div"+ids).style.display='none';
				tot_price_cal();
			}
		}
	}
	else
	{
		if(suppl_nm=="")
		{
			document.getElementById("plus_sm,"+pre_id).style.display='block';
			document.getElementById("remov_sm,"+pre_id).style.display='block';
			document.getElementById("stone_div"+ids).style.display='none';
		}
		else
		{
			if(document.getElementById('cat_name'+ids).value!="" || document.getElementById('stn_size'+ids).value!="" || document.getElementById('stn_wght'+ids).value!="" || document.getElementById('quanty'+ids).value!="" || document.getElementById('tot_wght'+ids).value!="") 
			{	
				var c_var=confirm("Are you Sure Want to Remove this Row?");
				if(c_var==true)
				{
					document.getElementById('cat_name'+ids).value="";
					document.getElementById('stn_size'+ids).value="";
					document.getElementById('stn_wght'+ids).value="";
					document.getElementById('quanty'+ids).value="";
					document.getElementById('tot_wght'+ids).value="0.0000";
					document.getElementById("plus_sm,"+pre_id).style.display='block';
					document.getElementById("remov_sm,"+pre_id).style.display='block';
					document.getElementById("stone_div"+ids).style.display='none';
					tot_price_cal();
				}
				else
				{
					return false;
				}
			}
			else
			{
				document.getElementById("plus_sm,"+pre_id).style.display='block';
				document.getElementById("remov_sm,"+pre_id).style.display='block';
				document.getElementById("stone_div"+ids).style.display='none';
				tot_price_cal();
			}
		}
	}
	document.getElementById("cur_count").value=pre_id;	
}

function tot_price_cal()
{
	sum = 0;
	var cnt1=document.getElementById("cur_count").value;
	for(j=1;j<=cnt1;j++)
	{
		if(document.getElementById("tot_wght"+j).value!='')
		{
			var v1 = parseFloat(document.getElementById("tot_wght"+j).value);
		}
		else
		{
			var v1 = 0;
		}
		sum +=v1;
	}
	document.getElementById("final_wght").value = sum.toFixed(4);	
}

function quan_multiple(lp_val)
{	
	alert(lp_val);
	var prz=document.getElementById("stn_wght"+lp_val).value;
	var qty=document.getElementById("quanty"+lp_val).value;
	
	if(prz!='' && qty!='')
	{
		var tot_price=qty*prz;
		var num=tot_price.toFixed(4);
	}
	else
	{
		var num = '0.0000';
	}
	document.getElementById("tot_wght"+lp_val).value=num;
	tot_price_cal();	
}
function gold_cal()
{
	var v1 = document.getElementById("volum").value;
	var v2 = document.getElementById("gold_to_vol").value;
	
	if(v1.trim()!='' && v2.trim()!='')
	{
		var rslt = parseFloat(v1)/parseFloat(v2);
		document.getElementById("gold_wt").value =rslt.toFixed(2)+' g';
	}
	else
	{
		document.getElementById("gold_wt").value = '0.00 g';
	}
}
function des_no_div(ids)
{	
	var qurl ="?emp_id="+ids;
	$("#des_no_div").load("ajax/cad_design_AJAX.php"+qurl,function(response)
	{});
}
function form_load()
{	
	//var emp_id = document.getElementById("hdes_name").value;
	var des_id = document.getElementById("desin_no").value;
	if(document.getElementById("cad_type1").checked==true)
	{
		var check_id = document.getElementById("cad_type1").value;
	}
	else if(document.getElementById("cad_type2").checked==true)
	{
		var check_id = document.getElementById("cad_type2").value;
	}
	if(des_id.trim()!='')
	{
		window.location="cad_design_update.php?des_no="+des_id+"&rad_typ="+check_id;
	}
}
function reload_page(ids)
{	
	window.location="cad_design_update.php?rad_typ="+ids;
}
function form_submit()
{
	if(document.getElementById('app_dt').value=='')
	{
		alert('Please Enter the Date');    
		document.getElementById('app_dt').focus();  
		return false;
	}
	
	if(document.getElementById('st_tim').value=='')
	{
		alert('Please Enter the Starting Time');    
		document.getElementById('st_tim').focus();  
		return false;
	}
	if(document.getElementById('ed_tim').value=='')
	{
		alert('Please Enter the Ending Time');    
		document.getElementById('ed_tim').focus();  
		return false;
	}
	if(document.getElementById("radio1").checked==false && document.getElementById("radio2").checked==false && document.getElementById("radio3").checked==false)
	{
		alert('Please Select the Type');    
		document.getElementById('ed_tim').focus();  
		return false;
	}	
	var where_to= confirm("Do you really want to Submit the selected items?");
	if (where_to== true)
	{
		var des_id = document.getElementById("des_no").value;
		var emp_id = document.getElementById("emp_id").value;
		var app_dt = document.getElementById("app_dt").value;
		var st_tim = document.getElementById("st_tim").value;
		var ed_tim = document.getElementById("ed_tim").value;
		
		if(document.getElementById("radio1").checked==true)
		{
			var wait_dt = document.getElementById("wait_dt").value;
			var adm_nm = document.getElementById("adm_nm").value;
			var sts = 'waiting';
		}
		else
		{
			var wait_dt = "";
			var adm_nm = "";
			var sts = 'process';
		}
		if(document.getElementById("cad_type1").checked==true)
		{
			var cad_ty = document.getElementById("cad_type1").value;
		}
		else if(document.getElementById("cad_type2").checked==true)
		{
			var cad_ty = document.getElementById("cad_type2").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;
				//document.cur_des.submit();
				window.location="cad_design_update.php?des_no="+des_id+"$$"+emp_id+"&rad_typ="+cad_ty;
			}
		}			
		var qurl ="?des_no="+des_id+"&emp_id="+emp_id+"&app_dt="+app_dt+"&st_tim="+st_tim+"&ed_tim="+ed_tim+"&wait_dt="+wait_dt+"&adm_nm="+adm_nm+"&sts="+sts;
		//alert(qurl);
		xmlhttp.open("GET","ajax/cad_design_update_AJAX.php"+qurl,true);
		xmlhttp.send();
	}
	else
	{
		return false;	  
	}	
}
function stone_size_chage(ids,pg_id,lop)
{
	var queryString="ajax/stone_get_AJAX.php?cat_id="+ids+"&pg_id="+pg_id+"&lop="+lop;	
	if(pg_id==1)
	{
		$("#stn_size_div"+lop).load(queryString,function(response){});
	}
	else
	{
		$("#stn_wght_div"+lop).load(queryString,function(response)
		{
			if(document.getElementById("quanty"+lop).value.trim()!='')
			{
				quan_multiple(lop);
			}
		});
	}
}
function page_submit()
{
	if(document.getElementById('app_dt').value=='')
	{
		alert('Please Enter the Date');    
		document.getElementById('app_dt').focus();  
		return false;
	}
	
	if(document.getElementById('st_tim').value=='')
	{
		alert('Please Enter the Starting Time');    
		document.getElementById('st_tim').focus();  
		return false;
	}
	if(document.getElementById('ed_tim').value=='')
	{
		alert('Please Enter the Ending Time');    
		document.getElementById('ed_tim').focus();  
		return false;
	}
	if(document.getElementById("radio1").checked==false && document.getElementById("radio2").checked==false && document.getElementById("radio3").checked==false)
	{
		alert('Please Select the Type');    
		document.getElementById('ed_tim').focus();  
		return false;
	}
				
	if(document.getElementById("radio2").checked==true)
	{
		/*if(document.getElementById('imgInp').value=='')
		{
			alert('Please Choose the Cad Image');    
			document.getElementById('imgInp').focus();  
			$("#customDialog").hide();
			return false;
		}
		else*/ if(document.getElementById('imgInp').value!='')
		{
			var emp_phto=document.getElementById('imgInp').value; 			
			var b = document.getElementById('imgInp');
			var f = -1;		
			var oas;
			var filesize = b.files[0].size; // b.files[0].Size;
			var size1=filesize / (1024 * 1024);
			var ext = emp_phto.substring(emp_phto.lastIndexOf('.') + 1);
			//alert(ext);
			if(ext!="JPG" && ext !="JPEG" && ext!="jpg" && ext!="jpeg" && ext !="PNG" && ext!="png")
			{
				alert('Browse only .jpg,.jpeg,.png file for Cad Image');    
				document.getElementById('imgInp').focus();  
				return false;
			}			
		}
		/*var letters=/^\d+(?:\.\d+)?$/;
		if(document.getElementById('appr_wght').value=='')
		{
			alert('Please Enter the Approximate Weight');    
			document.getElementById('appr_wght').focus();
			return false;
		}		
		if(document.getElementById('appr_wght').value!='')
		{
			if(letters.test(document.getElementById('appr_wght').value)==false)  
			{
				alert('Approximate Weight Should have only Digits');  
				document.getElementById('appr_wght').focus();
				return false;  
			}
		}*/
		var letters=/^\d+([\,\.]\d+)*([\.]\d+)?$/;
		//var letters=/^\d+(?:\,\d+)*(?:\.\d+)?$/;
		if(document.getElementById('des_hgt').value=='')
		{
			alert('Please Enter the Design Height');    
			document.getElementById('des_hgt').focus();
			return false;
		}		
		else if(document.getElementById('des_hgt').value!='')
		{
			if(letters.test(document.getElementById('des_hgt').value)==false)  
			{
				alert('Design Height Should have only Digits');  
				document.getElementById('des_hgt').focus();
				return false;  
			}
		}
		var letters=/^\d+([\,\.]\d+)*([\.]\d+)?$/;
		if(document.getElementById('des_wth').value=='')
		{
			alert('Please Enter the Design Width');    
			document.getElementById('des_wth').focus();
			return false;
		}		
		else if(document.getElementById('des_wth').value!='')
		{
			if(letters.test(document.getElementById('des_wth').value)==false)  
			{
				alert('Design Width Should have only Digits');  
				document.getElementById('des_wth').focus();
				return false;  
			}
		}
		var letters=/^\d+(?:\.\d+)?$/;
		if(document.getElementById('volum').value=='')
		{
			alert('Please Enter the Cad Volume');    
			document.getElementById('volum').focus();
			return false;
		}		
		else if(document.getElementById('volum').value!='')
		{
			if(letters.test(document.getElementById('volum').value)==false)  
			{
				alert('Cad Volume Should have only Digits');  
				document.getElementById('volum').focus();
				return false;  
			}
		}
		var letters=/^\d+(?:\.\d+)?$/;
		if(document.getElementById('gold_to_vol').value=='')
		{
			alert('Please Enter the Gold to Volume');    
			document.getElementById('gold_to_vol').focus();
			return false;
		}		
		else if(document.getElementById('gold_to_vol').value!='')
		{
			if(letters.test(document.getElementById('gold_to_vol').value)==false)  
			{
				alert('Gold to Volume Should have only Digits');  
				document.getElementById('gold_to_vol').focus();
				return false;  
			}
		}
		var letters=/^\d+$/;
		if(document.getElementById('no_pce').value=='')
		{
			alert('Please Enter the No. of Piece');    
			document.getElementById('no_pce').focus(); 
			return false;
		}		
		else if(document.getElementById('no_pce').value!='')
		{
			if(letters.test(document.getElementById('no_pce').value)==false)  
			{
				alert('No. of Piece Should have only Digits');  
				document.getElementById('no_pce').focus();
				return false;  
			}
		}
		if(document.getElementById("des_caty").value.trim()=="Stone")
		{	
			var cnt1=document.getElementById("cur_count").value;
			for(j=1;j<=cnt1;j++)
			{
				var mate1=document.getElementById('cat_name'+j).value;
				if(mate1=="")
				{
					alert('Please select the Stone Shape'+j);
					document.getElementById('cat_name'+j).focus();
					$(".hide_div").hide;
					return false;
				}
				
				var stn_size=document.getElementById('stn_size'+j).value;
				if(stn_size=="")
				{
					alert('Please select the Stone Size'+j);
					document.getElementById('stn_size'+j).focus();
					$(".hide_div").hide;
					return false;
				}		
				else if(stn_size!="")
				{				
					var cnt1=document.getElementById("cur_count").value;
					//alert(amt);
					for(i=1;i<=cnt1;i++)
					{	
						var sup_name=document.getElementById('stn_size'+i).value;
						for(a=i+1;a<=cnt1;a++)
						{
							var sup_name1=document.getElementById('stn_size'+a).value;
							var areEqual = sup_name.toUpperCase() === sup_name1.toUpperCase();
							if(areEqual)
							{
								alert("Stone Size " +i+ " And Stone Size  " +a+ " are same.Please select The Different Stone Size .");
								document.getElementById('stn_size'+a).focus();
								$(".hide_div").hide;
								return false;
								
							}
						}
					}
				}			
				var quantity=document.getElementById('quanty'+j).value;
				if(quantity=="")
				{	
					alert("Please Enter the Quantity "+j);
					document.getElementById('quanty'+j).focus();
					$(".hide_div").hide;
					return false;		
				}			
				else if(quantity!="")
				{
					var letters1 =  /^\d+(?:\.\d{0,3})?$/;   
					if(letters1.test(document.getElementById('quanty'+j).value)==false)  
					{
						alert("Quantity must have Numeric value"+j);
						document.getElementById('quanty'+j).value='';
						document.getElementById('quanty'+j).focus();
						$(".hide_div").hide;
						return false;	
					}					
				}							
			}
		}
	}
	else if(document.getElementById("radio1").checked==true)
	{		
		if(document.getElementById('imgInp').value!='')
		{
			var emp_phto=document.getElementById('imgInp').value; 			
			var b = document.getElementById('imgInp');
			var f = -1;		
			var oas;
			var filesize = b.files[0].size; // b.files[0].Size;
			var size1=filesize / (1024 * 1024);
			var ext = emp_phto.substring(emp_phto.lastIndexOf('.') + 1);
			//alert(ext);
			if(ext!="JPG" && ext !="JPEG" && ext!="jpg" && ext!="jpeg" && ext !="PNG" && ext!="png")
			{
				alert('Browse only .jpg,.jpeg,.png file for Cad Image');    
				document.getElementById('imgInp').focus();  
				return false;
			}			
		}
		var letters=/^\d+([\,]\d+)*([\.]\d+)?$/;
		if(document.getElementById('des_hgt').value!='')
		{
			if(letters.test(document.getElementById('des_hgt').value)==false)  
			{
				alert('Design Height Should have only Digits');  
				document.getElementById('des_hgt').focus();
				return false;  
			}
		}
		var letters=/^\d+([\,]\d+)*([\.]\d+)?$/;
		if(document.getElementById('des_wth').value!='')
		{
			if(letters.test(document.getElementById('des_wth').value)==false)  
			{
				alert('Design Width Should have only Digits');  
				document.getElementById('des_wth').focus();
				return false;  
			}
		}
		var letters=/^\d+(?:\.\d+)?$/;
		if(document.getElementById('volum').value!='')
		{
			if(letters.test(document.getElementById('volum').value)==false)  
			{
				alert('Cad Volume Should have only Digits');  
				document.getElementById('volum').focus();
				return false;  
			}
		}
		var letters=/^\d+(?:\.\d+)?$/;
		if(document.getElementById('gold_to_vol').value!='')
		{
			if(letters.test(document.getElementById('gold_to_vol').value)==false)  
			{
				alert('Gold to Volume Should have only Digits');  
				document.getElementById('gold_to_vol').focus();
				return false;  
			}
		}	
		var letters=/^\d+$/;
		if(document.getElementById('no_pce').value=='')
		{
			alert('Please Enter the No. of Piece');    
			document.getElementById('no_pce').focus(); 
			return false;
		}		
		else if(document.getElementById('no_pce').value!='')
		{
			if(letters.test(document.getElementById('no_pce').value)==false)  
			{
				alert('No. of Piece Should have only Digits');  
				document.getElementById('no_pce').focus();
				return false;  
			}
		}
		if(document.getElementById("des_caty").value.trim()=="Stone")
		{
			var cnt1=document.getElementById("cur_count").value;
			for(j=1;j<=cnt1;j++)
			{
				var mate1=document.getElementById('cat_name'+j).value;
				if(mate1=="")
				{
					alert('Please select the Stone Shape'+j);
					document.getElementById('cat_name'+j).focus();
					$(".hide_div").hide;
					return false;
				}
				
				var stn_size=document.getElementById('stn_size'+j).value;
				if(stn_size=="")
				{
					alert('Please select the Stone Size'+j);
					document.getElementById('stn_size'+j).focus();
					$(".hide_div").hide;
					return false;
				}		
				else if(stn_size!="")
				{				
					var cnt1=document.getElementById("cur_count").value;
					//alert(amt);
					for(i=1;i<=cnt1;i++)
					{	
						var sup_name=document.getElementById('stn_size'+i).value;
						for(a=i+1;a<=cnt1;a++)
						{
							var sup_name1=document.getElementById('stn_size'+a).value;
							var areEqual = sup_name.toUpperCase() === sup_name1.toUpperCase();
							if(areEqual)
							{
								alert("Stone Size " +i+ " And Stone Size  " +a+ " are same.Please select The Different Stone Size .");
								document.getElementById('stn_size'+a).focus();
								$(".hide_div").hide;
								return false;
								
							}
						}
					}
				}			
				var quantity=document.getElementById('quanty'+j).value;
				if(quantity=="")
				{	
					alert("Please Enter the Quantity "+j);
					document.getElementById('quanty'+j).focus();
					$(".hide_div").hide;
					return false;		
				}			
				else if(quantity!="")
				{
					var letters1 =  /^\d+(?:\.\d{0,3})?$/;   
					if(letters1.test(document.getElementById('quanty'+j).value)==false)  
					{
						alert("Quantity must have Numeric value"+j);
						document.getElementById('quanty'+j).value='';
						document.getElementById('quanty'+j).focus();
						$(".hide_div").hide;
						return false;	
					}					
				}							
			}
		}
		if(document.getElementById('wait_dt').value=='')
		{
			alert('Please Enter the Approved Date');    
			document.getElementById('wait_dt').focus();  
			return false;
		}
	}
	
	var where_to= confirm("Do you really want to Submit the selected items?");
	if (where_to== true)
	{
		document.cur_des.submit();
	}
	else
	{
		return false;	  
	}	
}

function hide_sho(ids)
{
	if(ids==1)
	{
		document.getElementById("desin_div").style.display='block';
		document.getElementById("wait_div").style.display='block';
		document.getElementById("sav_div").style.display='none';
		document.getElementById("fins_div").style.display='block';
	}
	else if(ids==2)
	{
		document.getElementById("desin_div").style.display='block';
		document.getElementById("wait_div").style.display='none';
		document.getElementById("sav_div").style.display='none';
		document.getElementById("fins_div").style.display='block';
	}
	else if(ids==3)
	{
		document.getElementById("desin_div").style.display='none';
		document.getElementById("wait_div").style.display='none';
		document.getElementById("sav_div").style.display='block';
		document.getElementById("fins_div").style.display='block';
	}
}

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

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