﻿// ===================================================================
// Author: Matt Kruse <matt@ajaxtoolbox.com>
// WWW: http://www.AjaxToolbox.com/
//
// NOTICE: You may use this code for any purpose, commercial or
// private, without any further permission from the author. You may
// remove this notice from your final code if you wish, however it is
// appreciated by the author if at least my web site address is kept.
//
// You may *NOT* re-distribute this code in any way except through its
// use. That means, you can include it in your product, or your web
// site, or any other form where the code is actually being used. You
// may not put the plain javascript up on your site for download or
// include it in your javascript libraries for download. 
// If you wish to share this code with others, please just point them
// to the URL instead.
// Please DO NOT link directly to my .js files from your site. Copy
// the files to your server and use them there. Thank you.
// ===================================================================

function AjaxRequest(){var req =new Object();
req.timeout =null;
req.generateUniqueUrl =true;
req.url =window.location.href;
req.method ="GET";
req.async =true;
req.username =null;
req.password =null;
req.parameters =new Object();
req.requestIndex =AjaxRequest.numAjaxRequests++;
req.responseReceived =false;
req.groupName =null;
req.queryString ="";
req.responseText =null;
req.responseXML =null;
req.status =null;
req.statusText =null;
req.aborted =false;
req.xmlHttpRequest =null;
req.onTimeout=null;
req.onLoading=null;
req.onLoaded=null;
req.onInteractive=null;
req.onComplete=null;
req.onSuccess=null;
req.onError=null;
req.onGroupBegin=null;
req.onGroupEnd=null;
req.xmlHttpRequest =AjaxRequest.getXmlHttpRequest();
if(req.xmlHttpRequest==null){return null;}req.xmlHttpRequest.onreadystatechange =
function(){if(req==null || req.xmlHttpRequest==null){return;}if(req.xmlHttpRequest.readyState==1){req.onLoadingInternal(req);}if(req.xmlHttpRequest.readyState==2){req.onLoadedInternal(req);}if(req.xmlHttpRequest.readyState==3){req.onInteractiveInternal(req);}if(req.xmlHttpRequest.readyState==4){req.onCompleteInternal(req);}};
req.onLoadingInternalHandled=false;
req.onLoadedInternalHandled=false;
req.onInteractiveInternalHandled=false;
req.onCompleteInternalHandled=false;
req.onLoadingInternal=
function(){if(req.onLoadingInternalHandled){return;}AjaxRequest.numActiveAjaxRequests++;
if(AjaxRequest.numActiveAjaxRequests==1 && typeof(window['AjaxRequestBegin'])=="function"){AjaxRequestBegin();}if(req.groupName!=null){if(typeof(AjaxRequest.numActiveAjaxGroupRequests[req.groupName])=="undefined"){AjaxRequest.numActiveAjaxGroupRequests[req.groupName] =0;}AjaxRequest.numActiveAjaxGroupRequests[req.groupName]++;
if(AjaxRequest.numActiveAjaxGroupRequests[req.groupName]==1 && typeof(req.onGroupBegin)=="function"){req.onGroupBegin(req.groupName);}}if(typeof(req.onLoading)=="function"){req.onLoading(req);}req.onLoadingInternalHandled=true;};
req.onLoadedInternal=
function(){if(req.onLoadedInternalHandled){return;}if(typeof(req.onLoaded)=="function"){req.onLoaded(req);}req.onLoadedInternalHandled=true;};
req.onInteractiveInternal=
function(){if(req.onInteractiveInternalHandled){return;}if(typeof(req.onInteractive)=="function"){req.onInteractive(req);}req.onInteractiveInternalHandled=true;};
req.onCompleteInternal=
function(){if(req.onCompleteInternalHandled || req.aborted){return;}req.onCompleteInternalHandled=true;
AjaxRequest.numActiveAjaxRequests--;
if(AjaxRequest.numActiveAjaxRequests==0 && typeof(window['AjaxRequestEnd'])=="function"){AjaxRequestEnd(req.groupName);}if(req.groupName!=null){AjaxRequest.numActiveAjaxGroupRequests[req.groupName]--;
if(AjaxRequest.numActiveAjaxGroupRequests[req.groupName]==0 && typeof(req.onGroupEnd)=="function"){req.onGroupEnd(req.groupName);}}req.responseReceived =true;
req.status =req.xmlHttpRequest.status;
req.statusText =req.xmlHttpRequest.statusText;
req.responseText =req.xmlHttpRequest.responseText;
req.responseXML =req.xmlHttpRequest.responseXML;
if(typeof(req.onComplete)=="function"){req.onComplete(req);}if(req.xmlHttpRequest.status==200 && typeof(req.onSuccess)=="function"){req.onSuccess(req);}else if(typeof(req.onError)=="function"){req.onError(req);}delete req.xmlHttpRequest['onreadystatechange'];
req.xmlHttpRequest =null;};
req.onTimeoutInternal=
function(){if(req!=null && req.xmlHttpRequest!=null && !req.onCompleteInternalHandled){req.aborted =true;
req.xmlHttpRequest.abort();
AjaxRequest.numActiveAjaxRequests--;
if(AjaxRequest.numActiveAjaxRequests==0 && typeof(window['AjaxRequestEnd'])=="function"){AjaxRequestEnd(req.groupName);}if(req.groupName!=null){AjaxRequest.numActiveAjaxGroupRequests[req.groupName]--;
if(AjaxRequest.numActiveAjaxGroupRequests[req.groupName]==0 && typeof(req.onGroupEnd)=="function"){req.onGroupEnd(req.groupName);}}if(typeof(req.onTimeout)=="function"){req.onTimeout(req);}delete req.xmlHttpRequest['onreadystatechange'];
req.xmlHttpRequest =null;}};
req.process =
function(){if(req.xmlHttpRequest!=null){if(req.generateUniqueUrl && req.method=="GET"){req.parameters["AjaxRequestUniqueId"] =new Date().getTime() + "" + req.requestIndex;}var content =null;
for(var i in req.parameters){if(req.queryString.length>0){req.queryString +="&";}req.queryString +=encodeURIComponent(i) + "=" + encodeURIComponent(req.parameters[i]);}if(req.method=="GET"){if(req.queryString.length>0){req.url +=((req.url.indexOf("?")>-1)?"&":"?") + req.queryString;}}req.xmlHttpRequest.open(req.method,req.url,req.async,req.username,req.password);
if(req.method=="POST"){if(typeof(req.xmlHttpRequest.setRequestHeader)!="undefined"){req.xmlHttpRequest.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');}content =req.queryString;}if(req.timeout>0){setTimeout(req.onTimeoutInternal,req.timeout);}req.xmlHttpRequest.send(content);}};
req.handleArguments =
function(args){for(var i in args){if(typeof(req[i])=="undefined"){req.parameters[i] =args[i];}else{req[i] =args[i];}}};
req.getAllResponseHeaders =
function(){if(req.xmlHttpRequest!=null){if(req.responseReceived){return req.xmlHttpRequest.getAllResponseHeaders();}alert("Cannot getAllResponseHeaders because a response has not yet been received");}};
req.getResponseHeader =
function(headerName){if(req.xmlHttpRequest!=null){if(req.responseReceived){return req.xmlHttpRequest.getResponseHeader(headerName);}alert("Cannot getResponseHeader because a response has not yet been received");}};
return req;}AjaxRequest.getXmlHttpRequest =function(){if(window.XMLHttpRequest){return new XMLHttpRequest();}else if(window.ActiveXObject){/*@cc_on @*/
/*@if(@_jscript_version >=5)
try{return new ActiveXObject("Msxml2.XMLHTTP");}catch(e){try{return new ActiveXObject("Microsoft.XMLHTTP");}catch(E){return null;}}@end @*/}else{return null;}};
AjaxRequest.isActive =function(){return(AjaxRequest.numActiveAjaxRequests>0);};
AjaxRequest.get =function(args){AjaxRequest.doRequest("GET",args);};
AjaxRequest.post =function(args){AjaxRequest.doRequest("POST",args);};
AjaxRequest.doRequest =function(method,args){if(typeof(args)!="undefined" && args!=null){var myRequest =new AjaxRequest();
myRequest.method =method;
myRequest.handleArguments(args);
myRequest.process();}};
AjaxRequest.submit =function(theform, args){var myRequest =new AjaxRequest();
if(myRequest==null){return false;}var serializedForm =AjaxRequest.serializeForm(theform);
myRequest.method =theform.method.toUpperCase();
myRequest.url =theform.action;
myRequest.handleArguments(args);
myRequest.queryString =serializedForm;
myRequest.process();
return true;};
AjaxRequest.serializeForm =function(theform){var els =theform.elements;
var len =els.length;
var queryString ="";
this.addField =
function(name,value){if(queryString.length>0){queryString +="&";}queryString +=encodeURIComponent(name) + "=" + encodeURIComponent(value);};
for(var i=0;i<len;i++){var el =els[i];
if(!el.disabled){switch(el.type){case 'text': case 'password': case 'hidden': case 'textarea':
this.addField(el.name,el.value);
break;
case 'select-one':
if(el.selectedIndex>=0){this.addField(el.name,el.options[el.selectedIndex].value);}break;
case 'select-multiple':
for(var j=0;j<el.options.length;j++){if(el.options[j].selected){this.addField(el.name,el.options[j].value);}}break;
case 'checkbox': case 'radio':
if(el.checked){this.addField(el.name,el.value);}break;}}}return queryString;};
AjaxRequest.numActiveAjaxRequests =0;
AjaxRequest.numActiveAjaxGroupRequests =new Object();
AjaxRequest.numAjaxRequests =0;



function fieldFocus(thefield) {
     if (thefield.value == thefield.defaultValue) {
       thefield.value = '';
     }
   }
   function fieldBlur(thefield) {
     if (thefield.value == '') {
       thefield.value = thefield.defaultValue;
     }
   }


function preloading(displayname)
	{
		objloading = document.getElementById(displayname);
		objloading.innerHTML = '<center><img src="image/loading.gif"></center>';
	}
function trim(stringToTrim) {
	return stringToTrim.replace(/^\s+|\s+$/g,"");
}

function Load_PhongSachMenu()
{
AjaxRequest.get(
{
'url':'phongsach_quangnhan1972_show_menu.asp',
'onSuccess':function(req){
document.getElementById("display_left_menu").innerHTML = req.responseText; }
}
);
}


function Load_News()
{
var changeid=document.getElementById("news_list");
thamso ='newsid=';
thamso += changeid.options[changeid.selectedIndex].value;
preloading('display_news');
AjaxRequest.get(
{
'url':'phongsach_quangnhan1972_morenews.asp?'+thamso,
'onSuccess':function(req){
document.getElementById("display_news").innerHTML = req.responseText; }
}
);
}


function ShowRandomQuiz(id)
{
thamso = 'id=';
thamso += id;
preloading('show_random_quiz');
AjaxRequest.get(
{
'url':'giaitri_quangnhan1972_random_quiz.asp?'+thamso,
'onSuccess':function(req){
document.getElementById('show_random_quiz').innerHTML = req.responseText; }
}
);
}

function mark_quiz_selectbox(choice){
for(i=1;i<=document.random_quizform.choice.length;i++){
document.getElementById('quiz' + i).checked=false;
}
	document.getElementById(choice).checked=true;

}

function validate_quiz_choice(id) {
myOption = -1;
var opt;
for (i=1; i<= document.random_quizform.choice.length; i++) {
opt=document.getElementById('quiz' + i);    
if (opt.checked) { 
var userselect = document.getElementById('quiz' + i).value;
myOption = i + 1; 
break;
}
}
if (myOption == -1) {
document.getElementById("show_alert").innerHTML="<img src=\"image/alert.jpg\" border=0>&nbsp;<i><font color=red>Xin bấm vào <img src=\"image/unchecked.gif\" border=0> để chọn một đáp án</font></i>";
return (false);
}
thamso ='id=';
thamso += id;
thamso +='&choice=';
thamso += userselect;
preloading('show_random_quiz');
AjaxRequest.get(
{
'url':'giaitri_quangnhan1972_random_quizresult.asp?'+thamso,
'onSuccess':function(req){
document.getElementById("show_random_quiz").innerHTML = req.responseText; }
}
);
}


function View_Quiz_Result(quizid) {
thamso ='id=';
thamso += quizid;
thamso +='&choice=';
preloading('show_random_quiz');
AjaxRequest.get(
{
'url':'giaitri_quangnhan1972_random_quizresult.asp?'+thamso,
'onSuccess':function(req){
document.getElementById("show_random_quiz").innerHTML = req.responseText; }
}
);
}

function ShowMoreQuiz(page)
{
preloading('show_more_random_quiz');
AjaxRequest.get(
{
'url':'giaitri_quangnhan1972_more_quiz.asp?p='+page,
'onSuccess':function(req){
document.getElementById("show_more_random_quiz").innerHTML = req.responseText; }
}
);
}

function Close_MoreQuiz()
{
document.getElementById("show_more_random_quiz").innerHTML ="";
}


function SendQuizResult(quizid,choice)
{
 var email= trim(document.getElementById("sender_email_quizresult").value);
 if ((email==' ') || (email==null) || (email.indexOf(".") == -1) || (email.indexOf("@") == -1) || (email.length <6) ) 
 { 
alert("Địa chỉ email không hợp lệ!");
return (false);
 }
thamso='id=';
thamso+=quizid;
thamso+='&choice=';
thamso+=choice;
thamso+='&email=';
thamso+=email;
preloading('send_quiz_result');
AjaxRequest.get(
{
'url':'giaitri_quangnhan1972_send_quizresult.asp?'+thamso,
'onSuccess':function(req){
document.getElementById("send_quiz_result").innerHTML =req.responseText;  }
}
);
}

function Search_Result(page) {
		var searchby = document.getElementById("search_by");
		var searchinput = trim(document.getElementById("txtSearch").value);
		if (searchinput.length <2 || searchinput =="Nhập từ khóa tìm"){
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 (false);
}
		strquery  = "searchby=";
		strquery  += searchby.options[searchby.selectedIndex].value;
		strquery  += "&text=";
		strquery  += encodeURI(searchinput.split(' ').join('+'));
		strquery  += '&p=';
		strquery  += page;
preloading('display_search_result');
AjaxRequest.get(
{
'url':'phongsach_quangnhan1972_quicksearchresult.asp?'+strquery,
'onSuccess':function(req){document.getElementById("display_search_result").innerHTML = req.responseText; }
}
);
} 

function Search_Author_By_Alpha(Alpha, intPageNum,intRowNum,intSortBy)
{
thamso = 'alpha=';
thamso += Alpha;
thamso += '&p=';
thamso += intPageNum;
thamso += '&rownum=';
thamso += intRowNum;
thamso += '&orderby=';
thamso += intSortBy;
preloading('display_search_result');
AjaxRequest.get(
{
'url':'phongsach_quangnhan1972_search_author_by_alpha.asp?'+thamso,
'onSuccess':function(req){
document.getElementById("display_search_result").innerHTML = req.responseText; 
}
}
);
}

function Search_Title_By_Alpha(Alpha, intPageNum,intRowNum,intSortBy)
{
thamso = 'alpha=';
thamso += Alpha;
thamso += '&p=';
thamso += intPageNum;
thamso += '&rownum=';
thamso += intRowNum;
thamso += '&orderby=';
thamso += intSortBy;
preloading('display_search_result');
AjaxRequest.get(
{
'url':'phongsach_quangnhan1972_search_title_by_alpha.asp?'+thamso,
'onSuccess':function(req){
document.getElementById("display_search_result").innerHTML = req.responseText; 
}
}
);
}

function Close_Search_Result()
{
document.getElementById("display_search_result").innerHTML ='' 
}

function Load_Browse_All(intPageNum,intRowNum,intSortBy)
{
thamso = 'p=';
thamso += intPageNum;
thamso += '&rownum=';
thamso += intRowNum;
thamso += '&orderby=';
thamso += intSortBy;
preloading('display_browseall');
AjaxRequest.get(
{
'url':'giaitri_quangnhan1972_browseall.asp?'+thamso,
'onSuccess':function(req){
document.getElementById("display_browseall").innerHTML = req.responseText; 
}
}
);
}

function Load_AuthorList(intPageNum,intRowNum,intSortBy)
{
thamso = 'p=';
thamso += intPageNum;
thamso += '&rownum=';
thamso += intRowNum;
thamso += '&orderby=';
thamso += intSortBy;
preloading('show_selected_thread');
AjaxRequest.get(
{
'url':'phongsach_quangnhan1972_load_authorlist.asp?'+thamso,
'onSuccess':function(req){
document.getElementById("show_selected_thread").innerHTML = req.responseText; 
}
}
);
}

function Load_Author_Thread(strAuthor, intPageNum,intRowNum,intSortBy)
{
thamso = 'author=';
thamso += strAuthor;
thamso += '&p=';
thamso += intPageNum;
thamso += '&rownum=';
thamso += intRowNum;
thamso += '&orderby=';
thamso += intSortBy;
preloading('show_author_thread');
AjaxRequest.get(
{
'url':'phongsach_quangnhan1972_load_author_thread.asp?'+thamso,
'onSuccess':function(req){
document.getElementById("show_author_thread").innerHTML = req.responseText; 
}
}
);
}

function Load_Author_Thread1(strAuthor, intPageNum,intRowNum,intSortBy)
{
thamso = 'author=';
thamso += strAuthor;
thamso += '&p=';
thamso += intPageNum;
thamso += '&rownum=';
thamso += intRowNum;
thamso += '&orderby=';
thamso += intSortBy;
preloading('display_cungmottacgia');
AjaxRequest.get(
{
'url':'phongsach_quangnhan1972_load_author_thread1.asp?'+thamso,
'onSuccess':function(req){
document.getElementById("display_cungmottacgia").innerHTML = req.responseText; 
}
}
);
}


function Show_Thread_In_Category(intCatID, intPageNum,intRowNum,intSortBy)
{
thamso = 'cid=';
thamso += intCatID;
thamso +='&p=';
thamso += intPageNum;
thamso += '&rownum=';
thamso += intRowNum;
thamso += '&orderby=';
thamso += intSortBy;
scroll(0,0);
preloading('display_thread_in_incategory');
AjaxRequest.get(
{
'url':'phongsach_quangnhan1972_show_thread_in_category.asp?'+thamso,
'onSuccess':function(req){
document.getElementById("display_thread_in_incategory").innerHTML = req.responseText;}
}
);
}

function Show_Thread_In_Subject(intSubID, intPageNum,intRowNum,intSortBy)
{
thamso = 'sid=';
thamso += intSubID;
thamso +='&p=';
thamso += intPageNum;
thamso += '&rownum=';
thamso += intRowNum;
thamso += '&orderby=';
thamso += intSortBy;
scroll(0,0);
preloading('display_thread_in_subject');
AjaxRequest.get(
{
'url':'phongsach_quangnhan1972_show_thread_in_subject.asp?'+thamso,
'onSuccess':function(req){
document.getElementById("display_thread_in_subject").innerHTML = req.responseText;}
}
);
}


function Show_More_Thread_In_Subject(intSubID, intCurrentOrder)
{
thamso = 'sid=';
thamso += intSubID;
thamso +='&order=';
thamso += intCurrentOrder;
preloading('display_more_thread_in_subject');
AjaxRequest.get(
{
'url':'phongsach_quangnhan1972_show_more_thread_in_subject.asp?'+thamso,
'onSuccess':function(req){
document.getElementById("display_more_thread_in_subject").innerHTML = req.responseText;}
}
);
}


function Show_Title_In_Group(intGroupID)
{
thamso = 'topicid=';
thamso += intGroupID;
preloading('display_title_in_group');
AjaxRequest.get(
{
'url':'phongsach_quangnhan1972_show_title_in_group.asp?'+thamso,
'onSuccess':function(req){
document.getElementById("display_title_in_group").innerHTML = req.responseText;}
}
);
}


function Show_Chapter_In_Title(intTitleID)
{
thamso = 'tid=';
thamso += intTitleID;
preloading('display_chapter_in_title');
AjaxRequest.get(
{
'url':'phongsach_quangnhan1972_show_index.asp?'+thamso,
'onSuccess':function(req){
document.getElementById("display_chapter_in_title").innerHTML = req.responseText;}
}
);
}


function View_Chapter_In_Title(intTitleID, intChapterID)
{
scroll(0,0);
thamso = 'tid=';
thamso += intTitleID;
thamso += '&ctid=';
thamso += intChapterID;
preloading('display_main_content');
AjaxRequest.get(
{
'url':'phongsach_view_chapter_in_title.asp?'+thamso,
'onSuccess':function(req){
document.getElementById("display_main_content").innerHTML = req.responseText;}
}
);
}


function Show_Title_Same_Author(strAuthor)
{
thamso = 'author=';
thamso += strAuthor;
preloading('display_title_of_author');
AjaxRequest.get(
{
'url':'phongsach_quangnhan1972_show_title_of_author.asp?'+thamso,
'onSuccess':function(req){
document.getElementById("display_title_of_author").innerHTML = req.responseText;}
}
);
}

function Load_DanhNgon()
{
AjaxRequest.get(
{
'url':'load_danhngon.asp',
'onSuccess':function(req){
document.getElementById("displaydanhngon").innerHTML = req.responseText; }
}
);
}

function Load_Category18()
{
AjaxRequest.get(
{
'url':'phongsach_quangnhan1972_category_18.asp',
'onSuccess':function(req){
document.getElementById("display_category_18").innerHTML = req.responseText; }
}
);
}

function Load_Category1()
{
AjaxRequest.get(
{
'url':'phongsach_quangnhan1972_category_1.asp',
'onSuccess':function(req){
document.getElementById("display_category_1").innerHTML = req.responseText; }
}
);
}

function Load_Category19()
{
AjaxRequest.get(
{
'url':'phongsach_quangnhan1972_category_19.asp',
'onSuccess':function(req){
document.getElementById("display_category_19").innerHTML = req.responseText; }
}
);
}



function Load_BienDongDaySong()
{
AjaxRequest.get(
{
'url':'load_biendongdaysong.asp',
'onSuccess':function(req){
document.getElementById("displaybiendongdaysong").innerHTML = req.responseText; }
}
);
}

function Load_XemNhieuNhat()
{
AjaxRequest.get(
{
'url':'load_xemnhieunhat.asp',
'onSuccess':function(req){
document.getElementById("displayxemnhieunhat").innerHTML = req.responseText; }
}
);
}


function Load_SachHay()
{
AjaxRequest.get(
{
'url':'load_sachhay.asp',
'onSuccess':function(req){
document.getElementById("displaysachhay").innerHTML = req.responseText; }
}
);
}

function Load_DauLaSuThat()
{
AjaxRequest.get(
{
'url':'load_daulasuthat.asp',
'onSuccess':function(req){
document.getElementById("displaydaulasuthat").innerHTML = req.responseText; }
}
);
}

function Load_ChuaDangXong()
{
AjaxRequest.get(
{
'url':'load_chuadangxong.asp',
'onSuccess':function(req){
document.getElementById("displaychuadangxong").innerHTML = req.responseText; }
}
);
}

function Load_ThongKe()
{
AjaxRequest.get(
{
'url':'phongsach_quangnhan1972_thongke.asp',
'onSuccess':function(req){
document.getElementById("display_thongke").innerHTML = req.responseText; }
}
);
}

function Load_Ad()
{
AjaxRequest.get(
{
'url':'load_advertising.asp',
'onSuccess':function(req){
document.getElementById("displayad").innerHTML = req.responseText; }
}
);
}

function Load_Subject()
{
AjaxRequest.get(
{
'url':'load_show_subject.asp',
'onSuccess':function(req){
document.getElementById("display_subject").innerHTML = req.responseText; }
}
);
}

