// JavaScript Document
var callLoadingId;
var callBackDisplayId;


function bkkLoading() {
	if( !$(callLoadingId) ) return false;
	if( $(callBackDisplayId) ) {
		var pW = $(callBackDisplayId).offsetWidth;
		var pH = $(callBackDisplayId).offsetHeight;
		
		$(callLoadingId).style.width = pW + 'px';
		$(callLoadingId).style.height = pH + 'px';
	}
   $(callLoadingId).style.display = '';
}
function bkkUnloading() {
	if( $(callLoadingId) )
		$(callLoadingId).style.display = 'none';
}




/* Price Table */
function priceTableLoad(url) {
	new Ajax.Request(
						url,
						{
							method:'get',
							postBody:'',
							onComplete:function(xhr) {
								var ctype = xhr.getResponseHeader("Content-Type");
								ctype = ctype.toLowerCase();
								
								priceTableCallBack(ctype, xhr);
							}
						}
					);
}
function priceTableCallBack(contType, xhr) {
	if(xhr.status == 200) {
		if(contType.toLowerCase().match("text/plain") || contType.toLowerCase().match("text/html")) {
			$(callBackDisplayId).innerHTML = xhr.responseText;
		}
		else {
			eval( xhr.responseText );
		}
	}
	else {
		alert( 'Call Price Fail?' );
	}
	bkkUnloading();
}


function callPriceTable(request, loadingId, displayId) {
	callLoadingId = loadingId;
	callBackDisplayId = displayId;
	
	bkkLoading();
	
	var requestUrl = callUrl;
		requestUrl += '/';
		requestUrl += request;
		
		requestUrl += '&dummy='+ (new Date()).getTime();
	
	priceTableLoad(requestUrl);
	return false;
}


function priceMenuTab_select( id ) {
	if( !$( id ) ) return;
	$( id ).className = 'hilight_red';
	
	var itabs = 1;
	while( true ) {
		if( 'price'+ itabs != id ) {
			if(!$('price'+ itabs) ) break;
			$( 'price'+ itabs ).className = '';
		}
		itabs++;
	}
}







/* Option1 */
function option1BlockLoad(url) {
	new Ajax.Request(
						url,
						{
							method:'get',
							postBody:'',
							onComplete:function(xhr) {
								var ctype = xhr.getResponseHeader("Content-Type");
								ctype = ctype.toLowerCase();
								
								option1BlockCallBack(ctype, xhr);
							}
						}
					);
}
function option1BlockCallBack(contType, xhr) {
	if(xhr.status == 200) {
		if(contType.toLowerCase().match("text/plain") || contType.toLowerCase().match("text/html")) {
			$(callBackDisplayId).innerHTML = xhr.responseText;
		}
		else {
			eval( xhr.responseText );
		}
	}
	else {
		alert( 'Require Content Fail?' );
	}
	bkkUnloading();
}


function callOption1Block(request, loadingId, displayId) {
	callLoadingId = loadingId;
	callBackDisplayId = displayId;
	bkkLoading();
	
	var requestUrl = callUrl;
		requestUrl += '/option1_block.php?';
		requestUrl += request;
		
		requestUrl += '&dummy='+ (new Date()).getTime();
	
	option1BlockLoad(requestUrl);
	return false;
}


function option1MenuTab_select( id ) {
	if( !$( id ) ) return;
	$( id ).className = 'hilight_blue';
	
	var itabs = 1;
	while( true ) {
		if( 'option1-'+ itabs != id ) {
			if(!$('option1-'+ itabs) ) break;
			$( 'option1-'+ itabs ).className = '';
		}
		itabs++;
	}
}






/* Utilities Block */
function utilitiesLoad(url) {
	new Ajax.Request(
						url,
						{
							method:'get',
							postBody:'',
							onComplete:function(xhr) {
								var ctype = xhr.getResponseHeader("Content-Type");
								ctype = ctype.toLowerCase();
								
								utilitiesBlockCallBack(ctype, xhr);
							}
						}
					);
}
function utilitiesBlockCallBack(contType, xhr) {
	if(xhr.status == 200) {
		if(contType.toLowerCase().match("text/plain") || contType.toLowerCase().match("text/html")) {
			$(callBackDisplayId).innerHTML = xhr.responseText;
		}
		else {
			eval( xhr.responseText );
		}
	}
	else {
		alert( 'Call Content Fail?' );
	}
	bkkUnloading();
}


function callUtilitiesBlock(request, loadingId, displayId) {
	callLoadingId = loadingId;
	callBackDisplayId = displayId;
	
	bkkLoading();
	
	var requestUrl = callUrl;
		requestUrl += '/';
		requestUrl += request;
		
		requestUrl += '&dummy='+ (new Date()).getTime();
	
	utilitiesLoad(requestUrl);
	return false;
}


function utilitiesMenuTab_select( id ) {
	if( !$( id ) ) return;
	$( id ).className = 'hilight_red';
	
	var umenu_tabs = new Array( 'activites', 'visiting', 'festival', 'events' );
	for( var i=0; i<umenu_tabs.length; i++ ) {
		if( umenu_tabs[i] + '_tab' != id ) {
			if( $( umenu_tabs[i] + '_tab' ) ) $( umenu_tabs[i] + '_tab' ).className = '';
		}
	}
}

