
// $Date: 2011-09-14 17:54:19 -0400 (Wed, 14 Sep 2011) $
// $Id: bbx.js 15 2011-09-14 21:54:19Z bbx $
// $Revision: 15 $

function bbxAjaxFail(t){
	alert('Error '+t.status+' -- '+t.statusText);
}
function bbxAjaxAlert(t){
	if(t.responseText!==''){
		alert(t.responseText);
	}
}

function bbxAjaxResponseHandler(r) {

/* Terminate your AJAX-invoked PHP code with:
 *

header('Content-type: application/json');
print(json_encode(array(
	'addClassName' => array(
		array('xmlId42', 'uiErr'),
		array('xmlId47', 'fooClass'),
		array('xmlId47', 'fooClassTwo'),
	),
	'alert' => 'some message!',
	'callback' => 'someFuncName',
	'callbackArg' => array(
		'id' => 42,
		'arg2' => 'cheese'
	),
	'redirect' => './home.phtml'
)));

 *
 */

	// ProtoType will have set this property of 'r' having seen the JSON
	// content-type in the HTTP response.
	var response = r.responseJSON;

	// First do changes to the DOM in case there's also an alert().
	if ( response.addClassName instanceof Array ) {
		response.addClassName.each(function(e){
			e[0].addClassName(e[1]);
		});
	}

	// Next invoke any additional javascript function passing the entire
	// response along.
	if ( response.callback ) {
		eval( response.callback+'('+(response.callbackArg?'response.callbackArg':'')+')' );
	}

	if ( response.alert ) {
		alert(response.alert);
	}
	if ( response.redirect ) {
		document.location.href = response.redirect;
	}

}

function bbxCenterObj(obj,mode){
	obj=$(obj);
	
	if(mode==undefined){
		mode='';
	}
	if(mode!='V'){
		w=obj.getWidth();
		vW= document.viewport.getWidth();
		left=(vW-w)/2;
		left=Math.floor(left);
		if(left<0){ left=0; }
		obj.style.left=left+'px';
	}
	if(mode!='H'){
		h=obj.getHeight();
		vH= document.viewport.getHeight();
		top=(vH-h)/2;
		top=Math.floor(top);
		if(top<0){ top=0; }
		obj.style.top=top+'px';
	}

	
}


