function fontPlus() {
    var divTemp = $('#contentText');
    var s = divTemp.css('font-size');
    if ((s.indexOf('px') > -1) && (s.indexOf('px') == (s.length - 2))) s = s.substring(0, s.indexOf('px'));
    divTemp.css({fontSize:(parseFloat(s) + 4) + 'px'});
}

function fontMinus() {
    var divTemp = $('#contentText');
    var s = divTemp.css('font-size');
    if ((s.indexOf('px') > -1) && (s.indexOf('px') == (s.length - 2))) s = s.substring(0, s.indexOf('px'));
    divTemp.css({fontSize:(parseFloat(s) - 4) + 'px'});
}

function fontDefault() {
    var divTemp = $('#contentText');
    divTemp.css({fontSize:"16px"});
}


function voiceSpeak(textVoice, sexVoice) {
	voiceCancel();
	$("#void-pause").show();
	$("#void-stop").show();
	var stripedHtml = $("<div>").html($("#"+textVoice).html()).text();
    responsiveVoice.speak(stripedHtml,$("#"+sexVoice).val());	
}

function voiceCancel() {
    responsiveVoice.cancel();
	$("#void-pause").hide();
	$("#void-resume").hide();
	$("#void-stop").hide();
}

function voicePause() {
    responsiveVoice.pause();
	$("#void-resume").show();
}

function voiceResume() {
	$("#void-resume").hide();
    responsiveVoice.resume();	
}

function setTuongPhan(vltuongphan) {
	if (vltuongphan == 3) {
		$("#main-body").css("background-color", "#FFF");
		$("#tuongphan").val(3);
	} else {
		if (vltuongphan == 0) {
			$("#main-body").css("background-color", "#DCDCDC");
			$("#tuongphan").val(0);
		} else {
			if (vltuongphan == 1) {
				$("#main-body").css("background-color", "#F5F5F5");
				$("#tuongphan").val(1);
			} else if (vltuongphan == 2){
				$("#main-body").css("background-color", "#F8F8FF");
				$("#tuongphan").val(2);
			} else {
				$("#main-body").css("background-color", "#FFFFFF");
				$("#tuongphan").val(3);
			}
		}
	}
}

function tangTuongPhan() {
	var tuongphan = $("#tuongphan").val();
	if (tuongphan < 3) {
		tuongphan = tuongphan + 1;
		setTuongPhan(tuongphan);
	} else if (tuongphan == 3) {
		setTuongPhan(tuongphan);
	}
}

function giamTuongPhan() {
	var tuongphan = $("#tuongphan").val();
	if (tuongphan > 0) {
		tuongphan = tuongphan - 1;
		setTuongPhan(tuongphan);
	}else if (tuongphan = 0) {
		setTuongPhan(tuongphan);
	}
}

function printPage(elementId) {
    
	var divToPrint=document.getElementById(elementId);
	newWin= window.open("");
	newWin.document.write(divToPrint.outerHTML);
	newWin.print();
	newWin.close();
}

function submitFormCaptcha() {
    var response = grecaptcha.getResponse();
    if(response.length == 0) {
        $("#g-recaptcha-error").html("<span style='color:red;'>This field is required.</span>");
        return false;
    }
    return true;
};

function verifyCaptcha() {
    $("#g-recaptcha-error").html("");
}

function loadMetaTag(imageURL) {
    $("#imageFB").setAttribute("content", imageURL);
}

function cutStr(chuoi, giatri){
	var catchuoi, vitri, laychuoi;	
	if(chuoi.length > giatri){		
		catchuoi = chuoi.substring(0,giatri);
		vitri = catchuoi.lastIndexOf(" ");
		laychuoi = chuoi.substring(0,vitri);
		laychuoi = laychuoi + " ...";
		return laychuoi;
	}else{
		return chuoi;	
	}
} 

function openVideo() {
	var tabcontent, tablinks, clientWidth;
	tabcontent = document.getElementsByClassName("cover-img");
	tabcontent[0].style.display = "none";	

	tablinks = document.getElementsByClassName("video");
	clientWidth = tablinks[0].parentElement.parentElement.clientWidth;
	document.getElementById("iframeTag").width = clientWidth + 'px'
	document.getElementById("iframeTag").height = (clientWidth * 9 / 16) + 'px'
	document.getElementById("iframeTag").src=document.getElementById("iframeTag").src + '&autoplay=1';
	tablinks[0].style.display = "block";
}


function beginP() {
	var tabpage = document.getElementsByClassName("relatedentry");
	for (i = 0; i < tabpage.length; i++) {
		tabpage[i].style.display = "none";
	}
	document.getElementById("curPage").value = "0";
	document.getElementById("0").style.display = "flex";	
}
function endP() {
	var tabpage = document.getElementsByClassName("relatedentry");
	var endPage = document.getElementById("totalPage").value;
	for (i = 0; i < tabpage.length; i++) {
		tabpage[i].style.display = "none";
	}	
	document.getElementById("curPage").value = endPage;
	document.getElementById(endPage).style.display = "flex";	
}
function previousP() {
	var tabpage = document.getElementsByClassName("relatedentry");
	var endPage = document.getElementById("totalPage").value;
	var curPage = document.getElementById("curPage").value;
	if (curPage == '0') {
		return;
	}
	for (i = 0; i < tabpage.length; i++) {
		tabpage[i].style.display = "none";
	}	
	document.getElementById("curPage").value = Number(curPage) - 1;
	document.getElementById(Number(curPage) - 1).style.display = "flex";
}
function nextP() {
	var tabpage = document.getElementsByClassName("relatedentry");
	var endPage = document.getElementById("totalPage").value;
	var curPage = document.getElementById("curPage").value;
	if (curPage == endPage) {
		return;
	}
	for (i = 0; i < tabpage.length; i++) {
		tabpage[i].style.display = "none";
	}	
	document.getElementById("curPage").value = Number(curPage) + 1;
	document.getElementById(Number(curPage) + 1).style.display = "flex";
}
	
