// JavaScript Document
function getHostName(){
	var domainName="";
	var hostName=window.location.hostname;
	if(hostName=='10.10.10.30'){domainName='http://10.10.10.30/cricket/'}
	else if(hostName.indexOf('jil.in')>-1){domainName='http://'+hostName+'/cricket/'}
	else{if(window.location.protocol=='https:'){domainName='https://'+hostName+'/'}
	else{domainName='http://'+hostName+'/'}}
	return domainName
}


function createHeadtitle(tVal, toId) {
		var tValue = tVal.trim();
		document.getElementById(toId).value = StriptSpecialCharacters(tValue);
	}



function StriptSpecialCharacters(characterTotal)
	{
		var chars = /^([A-Za-z0-9\ ])$/;  
		var newChar = "";
		var oldChar = characterTotal.split("");
		for(var q=0; q<oldChar.length;q++){
			if(oldChar[q].match(chars))
			{
				newChar = newChar + oldChar[q].toString().toLowerCase();
			}
		}
		//return newChar.replace(/\s+/g, "-");
		
		var newChar = newChar.replace(/\s+/g, "-");
		
		// remove last dash from string
		var lastStr = newChar.substring(newChar.length - 1, newChar.length);
		if(lastStr == '-'){
			var newChar = newChar.substring(0, newChar.length-1);
		}
		
		return newChar;
		
	}

function RemoveLastDash(newChar){
	//var newChar = "nstr-asDF-";
	//alert(newChar)
	var lastStr = newChar.substring(newChar.length - 1, newChar.length);
	if(lastStr == '-'){
		var newChar = newChar.substring(0, newChar.length-1);
	}
	
	//var nchar = newChar.replace(/-[^-]*$/, "");
	return newChar;
	//alert(newChar);
}


<!--AUTO FILL FOR SEO TITLE, KEYWORDS, DESC---!>
 function SpecialCharacters(characterTotal)
 {
	var chars = /^([A-Za-z0-9\ ])$/; 
	var newChar = "";
	var oldChar = characterTotal.split("");
	for(var q=0; q<oldChar.length;q++){
		if(oldChar[q].match(chars))
		{
			newChar = newChar + oldChar[q].toString();
		}
	}
	return newChar;
 }
	function createHeading(tVal, toId){
	document.getElementById(toId).value = SpecialCharacters(tVal);

 }
 <!-----  END ---->
 
 
 var IE  = document.all?true:false;

 function onlyCharacters(e) {
	var chars = /^([A-Za-z0-9\ ])$/;
	if(!IE){
		var wkey = e.which;
	}else{
		var wkey = window.event.keyCode;
	}
	 var character = String.fromCharCode(wkey);

	if((wkey==0)||(wkey==8)){	return;	}
	//if((wkey<48)||(wkey>57))
	if(!character.match(chars))
	{
		if(IE){		e.returnValue = false;	}
		else{	return false;	}
	}
}

<!-----  CHECK FOR UNIQUE URL ---->
$(document).ready(function(){
	/*$("#url_name").blur(function(){
							 
		var url_name = 'url_name';
		var url_val = $(this).attr('value');
		var tbl_name = 'cric_players';
		//alert('hi-'+url_val);
		var prev_url_name = $("#prev_url_name").attr('value');
		if(prev_url_name != url_val){
			check_duplicate_url(url_name, url_val, tbl_name);
		}

	});*/
	
});

function check_duplicate_url(url_name, url_val, tbl_name){
	
	var prev_url_name = $("#prev_url_name").attr('value');
	//alert(prev_url_name);

if(prev_url_name != url_val)
	{
	
		var url = getHostName()+'admin/common/unique_url';
		var imgsrc = getHostName()+'assets/img/lazy-loader.gif';
		$("#urlmsg").html("<img src='"+imgsrc+"'>");
	
		var cat_id = '';
		//alert(url_name+'-'+tbl_name);
		var myData = {'url_name': url_name, 'url_val': url_val, 'tbl_name': tbl_name, 'cat_id': cat_id};
		$.post(url, myData, function(vdata){
			
			if(vdata == 'N'){
				
				$("#urlmsg").html("Choose different url");
				$("#url_name").attr('value', '');
				$("#url_name").focus();
				return false;
			}else{
				$("#urlmsg").html("");
			}
		});
	}
	
	
}
<!-----  CHECK FOR UNIQUE URL ---->


$(document).ready(function(){
	$(".product_tab a").click(function(){
		var tabid = $(this).attr('id');
		product_steps(tabid);								   
	});
});

function product_steps(tabid){
	//alert('hi-'+tabid);
	$("div#p1, div#p2, div#p3, div#p4").hide();
	$(".product_tab a#p1, .product_tab a#p2, .product_tab a#p3, .product_tab a#p4").removeClass('btn-primary btn-success').addClass('btn-success');
	$(".product_tab a#"+tabid).removeClass('btn-success').addClass('btn-primary');
	$("div#"+tabid).show();
	
}

// CONFIRMATION BEOFRE ITEM DELETE
$(document).ready(function(){
	$(".crud-actions a i.fa-trash-o").click(function(){
		if(confirm("Are you sure to delete?")){
			return true;	
		}else{
			return false;
		}
	});
});


// MATCH 
$(document).ready(function(){
  // alert('N');	
	// adding team for toss
	$("input:checkbox[name='teams[]']").click(function(){
		var team_id = $(this).attr('value');
		var team_name = $(this).parent().text();
		
		if($(this).is(':checked')){
			$("#toss_block").append('<input type="radio" name="toss[]" value="'+team_id+'" id="'+team_id+'"  /> <span>'+team_name+'&nbsp;&nbsp;</span>');
		}else{
			$("#toss_block #"+ team_id).next('span').remove();
			$("#toss_block #"+ team_id).remove();
		}
	});
	
	// selected country with toss winner on page load
	$("input:checkbox[name='teams[]']").each(function(){
		//alert('ok');
		var team_id = $(this).attr('value');
		var team_name = $(this).parent().text();
		var toss_winner = $("#toss_winner").attr('value');
		
		var sal = "";
		if(team_id == toss_winner){
			var sal = " Checked = Checked ";	
		}
		$("#toss_block").append('<input type="radio" name="toss[]" value="'+team_id+'" id="'+team_id+'" '+sal+' /> <span>'+team_name+'&nbsp;&nbsp;</span>');											   
	});
	
	
});

// CALL MATCH AJAX DATA
	function ajax_data_match(id){
		//alert("hi"+id);
		var hostname = getHostName();
		var url = hostname+'admin/score_card/get_match_list';
		var myData = {'id': id};
		$.post(url, myData, function(vdata){
			$("#matchdd").html(vdata);
		});
	}
	
// CALL TEAM AJAX DATA
	function ajax_data_team(id){
		//alert("hi"+id);
		var hostname = getHostName();
		var url = hostname+'admin/score_card/get_team_list';
		var myData = {'id': id};
		$.post(url, myData, function(vdata){
			$("#teamdd").html(vdata);
		});
	}	

//yeardd
// CALL TEAM YEAR DATA
	function ajax_data_team_year(id){
		//alert("hi"+id);
		var hostname = getHostName();
		var url = hostname+'admin/score_card/get_team_year_list';
		var myData = {'id': id};
		$.post(url, myData, function(vdata){
			$("#yeardd").html(vdata);
		});
	}
	
	