//*************ajax functions
var handleFailure = function(o){
		try{
			//YAHOO.anitron.ajaxer.wait.hide();
		}catch(e){}
		try{
		alert(o.statusText);
		alert(o.argument.errorMsg);
		}catch(e){
			alert("System Error");
		}
	}
function checkAjaxError(o){
		var err =xmlTagVal(o.responseXML,"errormsg");
		if(err!=""){
			alert(err);
			return true;
		}
		return false;
}
function xmlTagVal(x,tag){
	
	try{
		//alert(x.getElementsByTagName(tag).childNodes(0));
		return x.getElementsByTagName(tag)[0].childNodes[0].nodeValue;
	}catch(e){
		return "";
	}
	 
}
function generalAjaxCall(url,aOptions){
	if(aOptions){
		
		//showWaiter();
	}
	var ajaxer = new Ajax.Request(url,{
	method: 'get',
  	onSuccess: generalAjaxSuccess,
	onFailure: handleFailure,
	argument: aOptions
	});
}
function showAjaxAlert(xml){
	var msg = xmlTagVal(xml,'alert');
	
	if(msg!=""){
		alert(msg);
	}
}
function generalAjaxSuccess(o){
		try{
			//YAHOO.anitron.ajaxer.wait.hide();
		}catch(e){}
	//alert(o.test());
	//$('test').value = "done";
	if(checkAjaxError(o)){
		return;
	}
	var aXML = o.responseXML;
	showAjaxAlert(aXML);
	updateDivOnSuccess(o);
	if(Object.isFunction(afterAjaxSuccess)){
		afterAjaxSuccess(o);
	}
}
function updateDivOnSuccess(o){
	try{
		if(o.request.options.argument.useResponseAsUpdateText){
			var updateDiv = o.request.options.argument.UpdateDiv;
			$(updateDiv).innerHTML = o.responseText;
		}
	}catch(e){}
}

//YAHOO.namespace("anitron.ajaxer");
// Initialize the temporary Panel to display while waiting for external content to load
function showWaiter(){
	if(!YAHOO.anitron.ajaxer.wait){
		YAHOO.anitron.ajaxer.wait = 
			new YAHOO.widget.Panel("wait",  
											{ width: "240px", 
											  fixedcenter: true, 
											  close: false, 
											  draggable: false, 
											  modal: true,
											  visible: false
											} 
										);
	

		YAHOO.anitron.ajaxer.wait.setHeader("Processing, please wait...");
		YAHOO.anitron.ajaxer.wait.setBody("<img src=\"http://us.i1.yimg.com/us.yimg.com/i/us/per/gr/gp/rel_interstitial_loading.gif\"/>");
		YAHOO.anitron.ajaxer.wait.render("ajaxWaiter");
	}
	//YAHOO.anitron.ajaxer.wait.show();
}
