﻿	var req;
	var url;
	function Initialize()
	{
		try
		{
			req=new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch(e)
		{
			try
			{
				req=new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch(oc)
			{
				req=null;
			}
		}
	
		if(!req&&typeof XMLHttpRequest!="undefined")
		{
			req=new XMLHttpRequest();
		}
	
	}
	function Goi_fun(callbackFunction)
	{}

		function voteloading(name)
	{
		obj = document.getElementById(name);
		obj.innerHTML = '<center><img src="image/loading8.gif"></center>';
	}



		function DisplayHTML(name)
	{
		obj = document.getElementById(name);
		obj.innerHTML = req.responseText;
		
	}

function SendQuery(url,callbackFunction,method,cache,request)
	{
			Initialize();
		if ( (req!=null) )
		{		
			req.onreadystatechange = function()
									{
									// only if req shows "complete"
										if (req.readyState == 4)
									    {
								        // only if "OK"
											if (req.status == 200)
											{
												// Process
												eval(callbackFunction);
											}
										}
									};
					
						
			// Cache data or not , default is yes(1)
	

			if ( cache != 1 )
			{
				url += "&rand="+Math.random()*1000;

			}
			
			// Use POST or GET method , default is GET
			if ( method == 'POST' )
			{
		        req.open("POST", url, true);
		        req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		        req.send(request);
			}
			else
			{										
				req.open("GET", url , true);
				//req.setRequestHeader("Pragma", "no-cache");// xoa cache 
				//req.setRequestHeader("Cache-Control", "must-revalidate");// xoa cache 
				//req.setRequestHeader("If-Modified-Since", document.lastModified);// xoa cache 
				req.send(null);
			}
		}
	}


function ADDVOTE(url)
	{		
			if(url != '' ){
			voteloading('voteresult');
			SendQuery(url,'DisplayHTML("voteresult")');}

}


function PlayMoreNews(url)
	{		
			if(url != '' ){
			voteloading('morenews');
			SendQuery(url,'DisplayHTML("morenews")');}

}

function GRADETHISLESSON(url)
	{		
			if(url != '' ){
			voteloading('rateresult');
			SendQuery(url,'DisplayHTML("rateresult")');}

}


function SETLANGUAGE(url)
	{		
			if(url != '' ){
			voteloading('language');
			SendQuery(url,'DisplayHTML("language")');}
}


function PlayDunCanLesson(url)
	{		
			if(url != '' ){
			voteloading('duncanlesson');
			SendQuery(url,'DisplayHTML("duncanlesson")');}
}

function PlayMoreSong(url)
	{		
			if(url != '' ){
			voteloading('playmoresong');
			SendQuery(url,'DisplayHTML("playmoresong")');}
}



function ShowDic(url)
	{		
			if(url != '' ){
			voteloading('staticdic');
			SendQuery(url,'DisplayHTML("staticdic")');}
}

function CHECKUSERNAME(url)
	{		
			if(url != '' ){
			resultloading('checkavailability');
			SendQuery(url,'DisplayHTML("checkavailability")');}
}


function CHECKEMAIL(url)
	{		
			if(url != '' ){
			resultloading('useremail');
			SendQuery(url,'DisplayHTML("useremail")');}
}



function Intro() {
muc= "id=";
muc += "1";
HuongDan("service/menuhuongdan.asp?"+muc);
	}
function Help() {
muc= "id=";
muc += "2";
HuongDan("service/menuhuongdan.asp?"+muc);
	}
function AddAdmin() {
muc= "id=";
muc += "3";
HuongDan("service/menuhuongdan.asp?"+muc);
	}
function RequestStory() {
muc= "id=";
muc += "4";
HuongDan("service/menuhuongdan.asp?"+muc);
	}
function GuiTruyen() {
muc= "id=";
muc += "5";
HuongDan("service/menuhuongdan.asp?"+muc);
	}

function Congtacvien() {
muc= "id=";
muc += "6";
HuongDan("service/menuhuongdan.asp?"+muc);
	}


function SearchMain() {
		var searchby = document.getElementById("searchby");
		var searchinput = document.getElementById("txtSearch").value;
		if (searchinput.length > 3){
		strquery  = "searchby=";
		strquery  += searchby.options[searchby.selectedIndex].value;
		strquery  += "&title=";
		strquery  += encodeURI(searchinput.split(' ').join('+'));
		quicksearch("quicksearchresult.asp?" + strquery);
		}else {
		alert("Bạn phải nhập vào nội dung tìm kiếm\nHoặc nội dung nhập vào quá ngắn!");
		}
		return true;
	}

function searchtruyen(url)
	{		
			if(url != '' ){
			playlistloading('searchresult');
			SendQuery(url,'DisplayHTML("searchresult")');}
}

function quicksearch(url)
	{		
			if(url != '' ){
			voteloading('quickresult');
			SendQuery(url,'DisplayHTML("quickresult")');}
}

function updatepicture(url)
	{		
			if(url != '' ){
			playlistloading('updatepicture');
			SendQuery(url,'DisplayHTML("updatepicture")');}
}

function changeFontColor(){
    var selectOpt = document.getElementById('color');
var y = document.getElementsByTagName('p');
    var td = document.getElementById('storycontent');
if (y)  {
for (i=0; i< y.length; i++)
{
y[i].style.color = selectOpt.options[selectOpt.selectedIndex].value;
}
}
if (td)  {
 td.style.color =  selectOpt.options[selectOpt.selectedIndex].value;
}
}
function ChangeFontSize() {
var fontOpt = document.getElementById('fontsize');
var thep = document.getElementsByTagName('p');
var thefont = document.getElementsByTagName('font');
var thetd = document.getElementById('storycontent');
if (thep)  {
for (i=0; i< thep.length; i++)
{
thep[i].style.fontSize = fontOpt.options[fontOpt.selectedIndex].value +"pt";
}
}
if (thefont)  {
for (i=0; i< thefont.length; i++)
{
thefont[i].style.fontSize = fontOpt.options[fontOpt.selectedIndex].value +"pt";
}
}


if (thetd){
thetd.style.fontSize =  fontOpt.options[fontOpt.selectedIndex].value +"pt";
}
}
function ChangeFontFace() {
var fontOpt = document.getElementById('face');
var thep = document.getElementsByTagName('p');
var thetd = document.getElementById('storycontent');
if (thep)  {
for (i=0; i< thep.length; i++)
{
thep[i].style.fontFamily =""+ fontOpt.options[fontOpt.selectedIndex].value;
}
}
if (thetd){
thetd.style.fontFamily =""+  fontOpt.options[fontOpt.selectedIndex].value;
}
}

function Inbai(newurl) { 
popupWin = window.open(newurl,'newpage','toolbar=no,location=no,menubar=no,scrollbars=yes,width=520,height=600,top=0,left=0,resizeable=yes,status=yes'); }

function GuiBai(x) { 
window.open("guibai.asp?id=" + x,"guibai","toolbar=no,location=no,menubar=no,scrollbars=no,width=350,height=400,top=0,left=0,resizeable=no,status=no"); }

function SendLessonComment(x) { 
window.open("sendlessoncomment.asp?lessonid=" + x,"SendLessonComment","toolbar=no,location=no,menubar=no,scrollbars=no,width=350,height=400,top=0,left=0,resizeable=no,status=no"); }

function SendComment(x) { 
window.open("sendcomment.asp?lessonid=" + x,"SendComment","toolbar=no,location=no,menubar=no,scrollbars=no,width=350,height=400,top=0,left=0,resizeable=no,status=no"); }

function DeleteMyLesson(x){
top.location.href = "deletemylesson.asp?" + x;
return true;
}




