function openwin(url, width, height) {

	window.open(url, '', 'width=' + width + ',height=' + height);

  }

function CheckAll(){

	var frm=document.formn;

	var count = frm.elements.length;



			if(document.formn.chk.checked == 0){

				for (i=0; i < count; i++){

					if(frm.elements[i].type=="checkbox"){

						frm.elements[i].checked = 0;



						document.formn.chk.checked=0;

					}

				}

			}

			if(document.formn.chk.checked == 1 ){

				for (i=0; i < count; i++){

					if(frm.elements[i].type=="checkbox"){

						frm.elements[i].checked = 1;



						document.formn.chk.checked=1;

					}

				}

			}



}

function chkdelete(){

	var frm=document.formn;

	count = frm.elements.length;

	var c=0;

	for (i=0; i < count; i++){

		if(frm.elements[i].checked == 1){

			c = 1;

		}

	}

	if(c == 0){

		alert('Please select a record first to delete.');

		return false;

	}

	if(c!=0){

		 return confirm('Are you sure you want to delete ....');

	}

}

function chksendmail(){

	var re_mail = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z])+$/;

	count = document.formn.elements.length;

	var c=0;

	for (i=0; i < count; i++){

		if(document.formn.elements[i].checked == 1){

			c = 1;

		}



	}

	if(c == 0){

		alert('First, select the record');

		return false;

	}

	else{



		if(document.formn.subject.value == ""){

				alert('Please enter subject.');

				document.formn.subject.focus();

				return false;

		}

		/*if(document.formn.message.value == ""){

				alert('Please enter message.');

				document.formn.message.focus();

				return false;

		}*/



	}

}

function CheckAllNew(){

	var frm=document.formn;

	var count = frm.elements.length;



			if(document.formn.chk.checked == 0 || document.formn.checkall.value=="Uncheck All"){

				for (i=0; i < count; i++){

					if(frm.elements[i].type=="checkbox"){

						frm.elements[i].checked = 0;



						document.formn.chk.checked=0;

					}

				}

			}

			if(document.formn.chk.checked == 1 || document.formn.checkall.value=="Check All"){

				for (i=0; i < count; i++){

					if(frm.elements[i].type=="checkbox"){

						frm.elements[i].checked = 1;



						document.formn.chk.checked=1;

					}

				}

			}

			if(document.formn.checkall.value=="Uncheck All"){

				document.formn.checkall.value="Check All";

			}else{

				document.formn.checkall.value="Uncheck All";

			}



}

function chkactivate(){

	var frm=document.formn;



	count = frm.elements.length;

	var c=0;

	for (i=0; i < count; i++){

		if(frm.elements[i].type=="checkbox"){

			if(frm.elements[i].checked == 1){

				c = 1;

			}

		}

	}

	if(c == 0){

		alert('Please select a record first ...');

		return false;

	}

}

function atleastone(){

	var frm=document.formn;

	count = frm.elements.length;

	var c=0;

	for (i=0; i < count; i++){

		if(frm.elements[i].type=="checkbox"){

			if(frm.elements[i].checked == 1){

				c = 1;

			}

		}

	}

	if(c == 0){

		alert('Please select a record first ...');

		return false;

	}

}

// function removeSpecialChars(inputVal)
// {
	 
// 	 let processed = inputVal.replace(/[^a-zA-Z0-9]+/g, '-');

// 	 processed = processed.replace(/^-+|-+$/g, '');
// 	 processed = processed.toString().toLowerCase();
// 	 return processed;
// }



$(document).on('click', '.btnEdit', function(e){

    var $this = $(this);

    var ediinput = $(this);

	var id = $(this).data('id');
	
    ediinput.hide();

    if(!$this.hasClass('.editTableGroup')) {

        $this.parents('.editTableGroup').find('.editTableInput').attr("readonly", false);

        $this.parents('.editTableGroup').find('.editTableInput').attr("disabled", false);

        $this.prev(".editTableInput").addClass('input_focus');

        $this.parents(".editTableGroup").append(function () {

            return '<div class="append_btns"><button class="edit_save" data-valid="'+id+'"><svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" viewBox="0 0 16 16"><path d="M16 8A8 8 0 1 1 0 8a8 8 0 0 1 16 0zm-3.97-3.03a.75.75 0 0 0-1.08.022L7.477 9.417 5.384 7.323a.75.75 0 0 0-1.06 1.06L6.97 11.03a.75.75 0 0 0 1.079-.02l3.992-4.99a.75.75 0 0 0-.01-1.05z"/></svg></button> <button class="edit_cancel"><svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" viewBox="0 0 16 16"><path d="M16 8A8 8 0 1 1 0 8a8 8 0 0 1 16 0zM5.354 4.646a.5.5 0 1 0-.708.708L7.293 8l-2.647 2.646a.5.5 0 0 0 .708.708L8 8.707l2.646 2.647a.5.5 0 0 0 .708-.708L8.707 8l2.647-2.646a.5.5 0 0 0-.708-.708L8 7.293 5.354 4.646z"/></svg></button></div>';

        });

    } else {

        $this.parents('.editTableGroup').find('.editTableInput').attr("readonly", true);

        $this.parents('.editTableGroup').find('.editTableInput').attr("disabled", true);

    }

	

    $(".edit_save").click(function(){

		var id = $(this).data('valid');
		var sname = $('#sname'+id).val();
	
        $.ajax({
            url: admin_link+'/updatAjaxdata.php',
            type: 'POST',
            data: {
				id : id,
				sname : sname
            },
            dataType: 'json',
            success: function(response) {

			  if(response.status == true)
				{
					console.log("Updated");
				}
				else{
					console.log("something went wrong");
				}

            }

        })

        $(this).parent().siblings(".editTableInput").attr("readonly", true);

        $this.parents('.editTableGroup').find('.editTableInput').attr("disabled", true);

        $(this).parent().siblings(".btnEdit").show();

        $(this).parent().siblings().removeClass('input_focus');

        $(this).parent().remove();

    });

    $(".edit_cancel").click(function(){

        $(this).parent().siblings(".editTableInput").attr("readonly", true);

        $this.parents('.editTableGroup').find('.editTableInput').attr("disabled", true);

        $(this).parent().siblings(".btnEdit").show();

        $(this).parent().siblings().removeClass('input_focus');

        $(this).parent().remove();

    });



});
function removeSpecialChars(inputVal)
{
	 
	 let processed = inputVal.replace(/[^a-zA-Z0-9]+/g, '-');
	
	 processed = processed.replace(/^-+|-+$/g, '');
	 processed = processed.toString().toLowerCase();
	 return processed;
}

