// JavaScript Document

var catChecked = false;

function check_ajax(ids)
{
    if (catChecked) return; // ❗ prevent repeated checking

    document.getElementById("lod").innerHTML =
        '<img src="images/elements/loaders/loader.gif" />';

    xmlhttp = new XMLHttpRequest();

    xmlhttp.onreadystatechange = function() {
        if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
            var res = xmlhttp.responseText.trim();

            if (res == "yes") {
                catChecked = true;  // prevent infinite loop
                alert("This category already exists");

                document.getElementById("lod").innerHTML = '';
				document.getElementById("cat_name").value='';
                document.getElementById("cat_name").focus();
                return false;
            } else {
                document.getElementById("lod").innerHTML = '';
            }
        }
    };

    var qurl = "?ajax_id=1&vals=" + ids;
    xmlhttp.open("GET","ajax/master_cad_cat_AJAX.php" + qurl, true);
    xmlhttp.send();
}
function conf_sub()
{
	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;
			if(res.trim()=="yes")
			{
				alert("This category is already Exist");	
				document.getElementById("lod").innerHTML =' ';
				document.getElementById("cat_name").focus();
				return false;
				
			}
			else
			{	
				var letters= /^[0-9]+$/;
				/*if(document.getElementById('cat_pnts').value=='')
				{
					alert('Please Enter Points');  
					document.getElementById('cat_pnts').focus();  
					return false;
				}
				else if(letters.test(document.getElementById('cat_pnts').value)==false)  
				{
					alert('Points Should have only Digits ');  
					document.getElementById('cat_pnts').focus();  
					return false;  
				}*/		
				
				var letters= /^(([0-1][0-9])|(2[0-3])):[0-5][0-9]$/;
				if(document.getElementById('cat_cst').value=='')
				{
					alert('Please Enter Category Time');  
					document.getElementById('cat_cst').focus();  
					return false;
				}
				else if(letters.test(document.getElementById('cat_cst').value)==false)  
				{
					alert('Time Should have only Digits ');  
					document.getElementById('cat_cst').focus();  
					return false;  
				}
				
				var letters=/^(0?[1-9]|[12][0-9]|3[01])[\/\-](0?[1-9]|1[012])[\/\-]\d{4}$/;
				if(document.getElementById('ca_date').value=='')
				{
					alert('Please Enter Category Date');  
					document.getElementById('ca_date').focus();  
					return false; 
				}
				else if(letters.test(document.getElementById('ca_date').value)==false)  
				{
					alert('Category Date must be in the given Format');  
					document.getElementById('ca_date').focus();  
					return false;  
				}
				
				
				
				document.getElementById("lod").innerHTML =' ';
				
				var where_to= confirm("Do you really want to Submit the Data?");
				if (where_to== true)
				{
					document.fm.submit();
				}
				else
				{
					return false;	
				}
			}
				
		}
	}
	
	var qurl ="?vals=" + ids
	//alert(qurl);
	xmlhttp.open("GET","ajax/master_cad_cat_AJAX.php"+qurl,true);
	xmlhttp.send();	
	
	
}

function auto_time(ids)
{
	var vls = document.getElementById(ids).value;
	var ln = vls.length;
	var res='';
	if(ln==2 ){ res = vls +":" ; }else{ res = vls;}
	
	document.getElementById(ids).value = res;
}

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

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


//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(statu_s==1)
	{	
		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/master_cad_cat_AJAX.php"+qurl,true);
		xmlhttp.send();	
	}
	else if(statu_s==2)
	{
		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;
				var splt = res.split("$*$");
				if(splt[0].trim()=="yes")
				{
					alert("This category already used in active stage");
					document.getElementById("ajaxres_"+ids).innerHTML=splt[1].trim();	
					return false;
					
				}
				else
				{
					document.getElementById("ajaxres_"+ids).innerHTML=splt[1].trim();
				}
				
			}
		}
		var qurl ="?ajax_id=3&ids="+ids+"&vals="+design_id;
		//alert(qurl);
		xmlhttp.open("GET","ajax/master_cad_cat_AJAX.php"+qurl,true);
		xmlhttp.send();
	}			
}



//DESIGN LIST PAGE, THIS IS FOR ACTIVE INACTIVE THE PAGES
function des_act_mem(design_id,statu_s,ids)
{
	document.getElementById("ajaxres_"+ids).innerHTML='<img src="images/elements/loaders/loader.gif" />';
	//alert(ids);
	if(statu_s==1)
	{
		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/master_membership_AJAX.php"+qurl,true);
		xmlhttp.send();	
	}
	else if(statu_s==2)
	{
		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;
				var splt = res.split("$*$");
				if(splt[0].trim()=="yes")
				{
					alert("This category already used in active stage");
					document.getElementById("ajaxres_"+ids).innerHTML=splt[1].trim();	
					return false;
					
				}
				else
				{
					document.getElementById("ajaxres_"+ids).innerHTML=splt[1].trim();						
				}
				
			}
		}
		var qurl ="?ajax_id=3&ids="+ids+"&vals="+design_id;
		//alert(qurl);
		xmlhttp.open("GET","ajax/master_membership_AJAX.php"+qurl,true);
		xmlhttp.send();
	}
}


//DESIGN LIST PAGE, THIS IS FOR ACTIVE INACTIVE THE PAGES
function des_act_opt(design_id,statu_s,ids)
{
	document.getElementById("ajaxres_"+ids).innerHTML='<img src="images/elements/loaders/loader.gif" />';
	//alert(ids);
	if(statu_s==1)
	{
		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/master_operation_AJAX.php"+qurl,true);
		xmlhttp.send();	
	}
	else if(statu_s==2)
	{
		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;
				var splt = res.split("$*$");
				if(splt[0].trim()=="yes")
				{
					alert("This category already used in active stage");
					document.getElementById("ajaxres_"+ids).innerHTML=splt[1].trim();
					return false;
				}
				else
				{
					document.getElementById("ajaxres_"+ids).innerHTML=splt[1].trim();
				}
			}
		}
		var qurl ="?ajax_id=3&ids="+ids+"&vals="+design_id;
		//alert(qurl);
		xmlhttp.open("GET","ajax/master_operation_AJAX.php"+qurl,true);
		xmlhttp.send();
	}
}