// JavaScript Document
function reload_chk()
{
	document.getElementById("reld_btn_view").style.display='block';
}

function des_sub_cat(sub_id,des_no)
{
	if(sub_id!='')
	{
		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)
			{
				//alert(xmlhttp.responseText);
			}
		}		
		var qurl ="?ajax_id=3&sub_id="+sub_id+"&design_id="+des_no;
		xmlhttp.open("GET","ajax/design_AJAX.php"+qurl,true);
		xmlhttp.send();				
	}
}

function des_no(ot)
{
	var ids=document.getElementById("cat_name").value;
	document.getElementById("dajax_lo").innerHTML='<img src="images/elements/loaders/loader.gif" />';
	//alert(ids);

	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)
		{
			
			document.getElementById("d_no").value=xmlhttp.responseText;
			document.getElementById("dajax_lo").innerHTML='';
		}
	}
	
	var qurl ="?ajax_id=1&cat_id=" + ids+"&ot="+ot;
	//alert(qurl);
	xmlhttp.open("GET","ajax/design_AJAX.php"+qurl,true);
	xmlhttp.send();
}

function des_sts()
{
	var ids=document.getElementById("design_no").value;
	document.getElementById("dajax_lo").innerHTML='<img src="images/elements/loaders/loader.gif" />';
	//alert(ids);
		
	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)
		{
			
			document.getElementById("d_sts").value=xmlhttp.responseText;
			document.getElementById("dajax_lo").innerHTML='';
		}
	}
	
	var qurl ="?ajax_id=1&des_id=" + ids
	//alert(qurl);
	xmlhttp.open("GET","ajax/design_sts_AJAX.php"+qurl,true);
	xmlhttp.send();				
}

//cat_name,d_no,hdes_name,imgInp
function fom_validate()
{
	if(document.getElementById('cat_name').value=='')
	{
		alert('Please Select the Category');  
		window.scrollTo(50,50);
		document.getElementById('cat_name').focus();  
		return false; 
	}
	if(document.getElementById('sub_cat_name').value=='')
	{
		alert('Please Select the Sub Category');  
		window.scrollTo(50,50);
		document.getElementById('sub_cat_name').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;  
		}
	}
	if(document.getElementById('hdes_name').value=='')
	{
		alert('Please Select the Hand Designer 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('hnd_date').value=='')
	{
		alert('Please Enter Hand Design Date');  
		document.getElementById('hnd_date').focus();  
		return false; 
	}
	else if(letters.test(document.getElementById('hnd_date').value)==false)  
	{
		alert('Hand Design Date must be in the given Format');  
		document.getElementById('hnd_date').focus();  
		return false;  
	}
		
	var letters=/^(0?[1-9]|[12][0-9]|3[01])[\/\-](0?[1-9]|1[012])[\/\-]\d{4}$/;
	if(document.getElementById('ddate').value=='')
	{
		alert('Please Enter Design Upload Date');  
		document.getElementById('ddate').focus();  
		return false; 
	}
	else if(letters.test(document.getElementById('ddate').value)==false)  
	{
		alert('Design Upload Date must be in the given Format');  
		document.getElementById('ddate').focus();  
		return false;  
	}
	
	if(document.getElementById('cad_cat').value=='')
	{
		alert('Please Select the Points');  
		window.scrollTo(50,50);
		document.getElementById('cad_cat').focus();  
		return false; 
	}
	
	if(document.getElementById('imgInp').value=='')
	{
		alert('Please Select the Design Image');
		document.getElementById('imgInp').focus();
		return false;
	}
	else
	{
		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);
		//alert(size1 + " MB");
		if (size1 > 1.0) 
		{
			alert('Please check the Design Image size[File Size Minimum 1MB]');
			return false;
			// return true;
		}
		var ext = emp_phto.substring(emp_phto.lastIndexOf('.') + 1);
		if(ext !="GIF" && ext!="gif" && ext !="JPEG" && ext!="jpeg" && ext !="JPG" && ext!="jpg" && ext !="PNG" && ext!="png" && ext !="BMP" && ext!="bmp")
		{
			alert('Browse only .jpg,.jpeg,.png,.gif file for Design Image');    
			document.getElementById('imgInp').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 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 reload_page() //this is for reloadin the page when selecting the comapny code
{
	var des_cd = document.getElementById('cat_name').value;
	var des_ot = document.getElementById('ot').value;
	//var fin_dt = encodeURIComponent(document.getElementById('fin_dt').value);
	
	window.location = 'design_list.php?master_cat_id='+ des_cd+"&ot="+des_ot;
}


function hid_sho()
{
	document.getElementById('img_div').style.display='block'
}

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 #EFFFFF";
}

function update_validate(ids) //THIS IS FOR VALIDATING UPDATE PAGE	
{
	if(ids==1)
	{
		if(document.getElementById("wax_upd").checked==true || document.getElementById("cad_upd").checked==true)
		{
		var x;
		var remark = prompt("Please Enter The Remarks", "");
	
		if (remark!=null) 
		{
			x =  remark;
			//alert(x);
		   var sc= document.getElementById("remark").value = x;
		   //alert(sc);
		}
		}
	}
	else if(ids==0)
	{
		if(document.getElementById("cad_upd").checked==true)
		{
		var x;
		var remark = prompt("Please Enter The Remarks", "");
	
		if (remark!=null) 
		{
			x =  remark;
			//alert(x);
		   var sc= document.getElementById("remark").value = x;
		   //alert(sc);
		}
		}
	}
	
	var where_to= confirm("Do you really want to Submit the Data?");
	if (where_to== true)
	{
		document.fm.submit();
	}
	else
	{
		return false;	
	}
}

function fom_cat_validate()
{
	if(document.getElementById('design_no').value=='')
	{
		alert('Please Select the Design No');  
		window.scrollTo(50,50);
		document.getElementById('design_no').focus();  
		return false; 
	}
	
	if(document.getElementById('imgInp').value=='')
	{
		alert('Please Select the Design Image');
		document.getElementById('imgInp').focus();
		return false;
	}
	else
	{
		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);
		//alert(size1 + " MB");
		if (size1 > 1.0) 
		{
			alert('Please check the Design Image size[File Size Minimum 1MB]');
			return false;
			// return true;
		}
		var ext = emp_phto.substring(emp_phto.lastIndexOf('.') + 1);
		if(ext !="GIF" && ext!="gif" && ext !="JPEG" && ext!="jpeg" && ext !="JPG" && ext!="jpg" && ext !="PNG" && ext!="png" && ext !="BMP" && ext!="bmp")
		{
			alert('Browse only .jpg,.jpeg,.png,.gif file for Design Image');    
			document.getElementById('imgInp').focus();  
			return false;
		}
		
	}
	
	var where_to= confirm("Do you really want to Submit the Data?");
	if (where_to== true)
	{
		document.fm_cat.submit();
	}
	else
	{
		return false;	
	}
}


//DESIGN LIST PAGE, THIS IS FOR ACTIVE INACTIVE THE PAGES
function des_act_ina(design_id,statu_s,ids)
{
	document.getElementById("ajaxres_"+ids).innerHTML='<img src="images/elements/loaders/loader.gif" />';
	//alert(ids);

	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)
		{
			//alert(xmlhttp.responseText);		
			document.getElementById("ajaxres_"+ids).innerHTML=xmlhttp.responseText;
		}
	}
	
	var qurl ="?ajax_id=2&ids="+ids+"&design_id="+design_id+"&statu_s="+statu_s;
	//alert(qurl);
	xmlhttp.open("GET","ajax/design_AJAX.php"+qurl,true);
	xmlhttp.send();				
}
