YAHOO.namespace("example.container");
var ajaxLoaderId = 'ajaxLoader';
var loadingMsg = "Loading...";
var ajaxResponseId  = 'ajaxResponse';
function showLoader(){
	        if (!YAHOO.example.container.wait) {
	            // Initialize the temporary Panel to display while waiting for external content to load
	           YAHOO.example.container.wait = 
	                    new YAHOO.widget.Panel("wait",  
	                                                    { width: "200px", 
	                                                   	  height: "20px",
	                                                      fixedcenter: true, 
	                                                      close: false, 
	                                                      draggable: false, 
	                                                      zindex:4,
	                                                      modal: true,
	                                                      visible: false
	                                                    } 
	                                                );
		}
		// hide any displayed message
		if(document.getElementById(ajaxResponseId)){
			document.getElementById(ajaxResponseId).innerHTML='';
		}
		// Show the Panel
		 document.getElementById(ajaxLoaderId).innerHTML=loadingMsg;
}
function hideLoader(callbackFunction){
 	
 	//YAHOO.example.container.wait.hide();
 	document.getElementById(ajaxLoaderId).innerHTML = '';
	if(callbackFunction != undefined){
	 	 //callback a function 
 		 var t=setTimeout(callbackFunction+"()",0);
	}

 	
 	//after 4 seconds the message will be disappeared
 	var t=setTimeout("hideAjaxMessage()",4000);
 	

}

function sendAjaxRequest(url, ajaxResponse, callbackFunction){
showLoader();
 var callback = {
            success : function(o) {
                ajaxResponse.innerHTML = o.responseText;
                ajaxResponse.style.visibility = "visible";
                hideLoader(callbackFunction);
            },
            failure : function(o) {
                ajaxResponse.innerHTML = o.responseText;
                ajaxResponse.style.visibility = "visible";
                ajaxResponse.innerHTML = "CONNECTION FAILED!";
                hideLoader(callbackFunction);
                return false;
            }
          }
//ajaxResponse.innerHTML = "";
// Connect to our data source and load the data
var conn = YAHOO.util.Connect.asyncRequest("POST", url, callback);
return true;
}

function getURL(link, object){
	var objectString = "";
	if(object != undefined && object != null)
	{
		for(var objectField in object)
		{
			if(objectString != "")
			{
				objectString += "&";
			}
			if(object[objectField] instanceof Array == false)
			{
				objectString += encodeURIComponent(objectField) + "=" + encodeURIComponent(object[objectField]);
			}
			else
			{
				for(var i = 0; i < object[objectField].length; i++)
				{
					objectString += encodeURIComponent(objectField) + "=" + encodeURIComponent(object[objectField][i]);
					if(i  < object[objectField].length - 1)
					{
						objectString += "&";
					}
				}
			}
		}
	}
	return link+"?"+objectString;

}

function addAjaxEvent(objectId, eventType, handler){
	return YAHOO.util.Event.on(objectId, eventType, handler);
}   

function hideAjaxMessage(){
		if(document.getElementById(ajaxResponseId)){
			document.getElementById(ajaxResponseId).innerHTML='';
		}
}
