var is_ajax_debug = false;

function getAjaxData(URL,params,func, interID)
{

	document.getElementById("divLoadingIMG").style.left = (document.body.clientWidth - document.getElementById("divLoadingIMG").clientWidth) /2 + "px";
	document.getElementById("divLoadingIMG").style.top  = (document.body.clientHeight - document.getElementById("divLoadingIMG").clientHeight) /2 + document.body.scrollTop + "px";



//	document.getElementById("divLoading").style.position = "absolute";
//	document.getElementById("divLoading").style.width =document.body.clientWidth;   
//	document.getElementById("divLoading").style.height=document.body.scrollHeight; 
//	document.getElementById("divLoading").style.top = "0px" ;
//	document.getElementById("divLoading").style.left= "0px" ;
		var ifmRef = document.getElementById("divLoading");
		ifmRef.style.display = "block" ;
		ifmRef.style.width = document.body.clientWidth;
		ifmRef.style.height = document.body.scrollHeight;
		ifmRef.style.top = "0px";
		ifmRef.style.left = "0px";
//		ifmRef.style.zIndex = "1";
		ifmRef.style.display = "block";


//	alert(document.getElementById("divLoading").style.height);
//	alert(document.body.offsetHeight);
	document.getElementById("divLoading").frameborder = "0";
	document.getElementById("divLoading").frameBorder = "0";

	document.getElementById("divLoading").style.opacity = "60";    
	document.getElementById("divLoading").style.MozOpacity = "0.6";
	document.getElementById("divLoading").style.filter = "alpha(opacity=60)";
	document.getElementById("divLoading").style.zIndex = "100";
	document.getElementById("divLoading").style.border = "none";
//	document.getElementById("divLoading").style.display = "block" ;

	var myAjax = new Ajax.Request( URL,
		{
			asynchronous: true,
			method: "post",
			parameters: params,
			onSuccess: function(xmlHttp){
				try {
					var data = xmlHttp.responseXML.getElementsByTagName('casest')[0].getAttribute("rtnMsg")
//					alert(data) ;
//					var data = xmlHttp.responseText ;
///					if(!ajaxReturnErrorCheck(data)) return;
				} catch(e) {
					var errorObj = {
						'e':e,
						'x':xmlHttp
					};
					ajax_debug(errorObj);
					return;
				}

				func(data);


//xmlHttp.onreadystatechange = function() {
     if(xmlHttp.readyState == 0) {//UNINITIALIZED
     }  else if(xmlHttp.readyState == 1) {//LOADING
     }  else if(xmlHttp.readyState == 2) {//LOADED
     }  else if(xmlHttp.readyState == 3) {//INTERACTIVE
     }  else if(xmlHttp.readyState == 4) {//COMPLETE
//    if(xmlHttp.status == 200) { //200 = o
	document.getElementById("divLoading").style.display = "none" ;
  //  }
     }
  //}

			},
			onFailure : function (request)
			{
				func("FAIL");
				return;
			}
		}
	);
}
function getAjaxHttp(URL,params,func, interID)
{


	var myAjax = new Ajax.Request( URL,
		{
			asynchronous: true,
			method: "post",
			parameters: params,
			onSuccess: function(xmlHttp){
				try {
					var data = xmlHttp ;
///					if(!ajaxReturnErrorCheck(data)) return;
				} catch(e) {
					var errorObj = {
						'e':e,
						'x':xmlHttp
					};
					ajax_debug(errorObj);
					return;
				}

				func(data);

			},
			onFailure : function (request)
			{
				func("FAIL");
				return;
			}
		}
	);
}


function doAjax(URL,pars,func)
{
	var myAjax = new Ajax.Request( URL,
		{
			parameters: pars,
			onSuccess: function(xmlHttp){
				func.call();
			}
		}
	);
}

function ajax_debug(data) {
	if(is_ajax_debug) {
		alert('AjaxCall : ' + data.e + ' - ' + data.x.responseText);
	}
}

function ajaxReturnErrorCheck(data) {
	if(data.resultCode == 'ERROR') {
		if(data.message) alert(data.message.replace(/\\n/gi, "\n"));

		if(data.result == 'not login') {
			Common.goHome();
		}
		else if(data.result == 'memo list') {
			document.location.href = Common.getRoot() + "memo/memomain/memomain_list";
		}

		return false;
	}

	return true;
}
