// 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" />'
	//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")
			{
				catChecked = true;  // prevent infinite loop
				alert("This Courier is already Exist");	
				document.getElementById("lod").innerHTML =' ';
				document.getElementById("cr_name").value="";
				document.getElementById("cr_name").focus();
				return false
			}
			else
			{
				document.getElementById("lod").innerHTML =' ';
			}
		}
	}

	var qurl ="?ajax_id=1&vals=" + ids
	//alert(qurl);
	xmlhttp.open("GET","ajax/master_cour_AJAX.php"+qurl,true);
	xmlhttp.send();	
}
function conf_sub()
{
				if(document.getElementById('cr_name').value=='')
				{
					alert('Please Enter The Courier Name');  
					document.getElementById('cr_name').focus();  
					return false; 
				}
				if(document.getElementById('cr_url').value=='')
				{
					alert('Please Enter Valid website URL');  
					document.getElementById('cr_url').focus();  
					return false; 
				}
				    var pattern = /^(https?:\/\/)?([a-zA-Z0-9.-]+\.[a-zA-Z]{2,})(\/.*)?$/;

				if(document.getElementById('cr_url').value!='')    
				{
					if(pattern.test(document.getElementById('cr_url').value)==false)  
					{
						alert('Website URL is not valid');  
						document.getElementById('cr_url').focus();  
						return false;  
					} 
				}

				if(document.getElementById('phon_no').value=='')
				{
					alert('Please Enter The Phone No');  
					document.getElementById('phon_no').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;	
				}
}


function conf_sub123()
{
	document.getElementById("lod").innerHTML = '<img src="images/elements/loaders/loader.gif" />'
	var ids = document.getElementById("cr_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 Courier is already Exist");	
				document.getElementById("lod").innerHTML =' ';
				document.getElementById("cr_name").focus();
				return false;
			}
			else
			{
alert(document.getElementById('cr_name').value);
	if(document.getElementById('cr_name').value=='')
				{
					alert('Please Enter The Courier Name');  
					document.getElementById('cr_name').focus();  
					return false; 
				}
				var letters=/(ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/; 
				if(document.getElementById('cr_url').value!='')    
				{
					/*alert('Please Enter the Email ID 1');  
					document.getElementById('e_id').focus();  
					return false;*/
					if(letters.test(document.getElementById('cr_url').value)==false)  
					{
						alert('Website URL is not valid');  
						document.getElementById('cr_url').focus();  
						return false;  
					} 
				}

				//var letters=/^(0?[1-9]|[12][0-9]|3[01])[\/\-](0?[1-9]|1[012])[\/\-]\d{4}$/;
				if(document.getElementById('phon_no').value=='')
				{
					alert('Please Enter The Phone No');  
					document.getElementById('phon_no').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_cour_AJAX.php"+qurl,true);
	xmlhttp.send();	

}


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 (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_cour_AJAX.php"+qurl,true);
	xmlhttp.send();
}