/*
	Code written by Thanachai Soontornwutikul.
	Copyright (C) 2008 Thanachai Soontornwutikul.
	All rights reserved.
	
	Provided exclusively for B.E.B.C. Co., Ltd. for commercial uses.
	
	Last modified:  March 8, 2008 at 11:34 PM
*/

var AjaxEnabled = isAjaxEnabled();

function setAjaxUsage(useAjax){

	var cookieDate = new Date();
	cookieDate.setTime(cookieDate.getTime()+(90*24*60*60*1000));
	var expires = cookieDate.toGMTString();

	if(useAjax==false){
		var cookieValue = 'no';
		AjaxEnabled = false;
	} else {
		var cookieValue = 'yes';
		AjaxEnabled = true;
	} 
	
	document.cookie = 'bebcsajax=' + cookieValue + '; expires=' + expires + '; path=/';

	return false;

}

function getCookie(name){
	if(document.cookie.length > 0){
		start_cookie = document.cookie.indexOf(name + "=");
		if(start_cookie!=-1){
			start_cookie = start_cookie + name.length + 1;
			end_cookie = document.cookie.indexOf(";",start_cookie);
			if(end_cookie == -1) end_cookie=document.cookie.length;
			return unescape(document.cookie.substring(start_cookie,end_cookie));
		}
	}
	return '';
}

function isAjaxEnabled(){
	
	var cookieValue = getCookie('bebcsajax');
	if(cookieValue=='no'){
		return false;
	} else {
		return false;  // DEBUG: Always disable Ajax
	}

}

function changeAjaxToEnabled(){
	$("#ajaxNotice").html(getAjaxNotice());
}

function changeAjaxToDisabled(){
	$("#ajaxNotice").html(getAjaxDisabledNotice());
}

function getInitialAjaxNotice(){

	if(AjaxEnabled){
		changeAjaxToEnabled();
	} else {
		changeAjaxToDisabled();
	}
	
}

function getAjaxNotice(){
	return 'This website makes use of <a href="http://en.wikipedia.org/wiki/Ajax_%28programming%29" rel="external" title="Show definition of Ajax (Wikipedia) in new window or tab">Ajax</a> to help loading pages faster.&nbsp;&nbsp;Back and Forward buttons may not work as expected.<br />If you experience problems such as broken language or page alignment, <a href="#" onclick="changeAjaxToDisabled(); return setAjaxUsage(false);" title="Click to disable Fast Page Loading">click here</a> to disable it.';
}

function getAjaxDisabledNotice(){
	return 'Fast page loading is temporarily disabled.'
	// return 'Fast page loading was disabled. You can <a href="#" onclick="changeAjaxToEnabled(); return setAjaxUsage(true);" title="Click to re-enable Fast Page Loading">click here</a> to enable it again.';
}