// image is loading flag 
 var ajaxLock = false;
 var loading = false;
 /**
  * Display the countdown from the session timeout upper limit.
  */
 function display(){ 
	
	 if ( miliseconds <= 0 ) { 
	     miliseconds = 9 
	     seconds--
	 }
	 
	 if ( seconds <= -1 ) { 
	     miliseconds = 0 
	     seconds++ 
	 } 
	 
	 if( seconds < 1 ) {
	 	document.counter.session_timeout.value = 0;
	 	new Ajax.Request('/async/killhttpsession/'+sessionId+'', {
		  onSuccess: function(transport) {
		 	location.reload(true);
		  }
		});
	 }
	 else {
	     miliseconds-- 
	     document.counter.session_timeout.value = seconds;// + "." + miliseconds;
	     setTimeout( "display()", 100, 'JavaScript');
     } 
} 

/**
 * This method makes an ajax call to the server
 * in an effort to retrieve an image associated with a 'latest offer' entity
 */
 function getOfferImage(fileID, offerID) {
	 if(false == loading) {
		loading = true;
		var triggerID = 'view_image_detail';
		var updateNodeId = 'offerdata';
		var url = '/getlatestofferimage/' + fileID + "/" + offerID + "/offerimage.html";
		var ajaxUpdater = new Ajax.Updater(
			updateNodeId,
			url,
			{
				method:'get',
				onSuccess: function () {
					loading = false;
				}
			}
		);
		var my_tooltip_1 = new Tooltip(triggerID, updateNodeId);
		Effect.Appear(updateNodeId);
	}
 }

/**
 * This method makes an ajax call to the server
 * in an effort to retrieve an image associated with a news item
 */
 function getNewsImage(newsItemID) {
	 if(false == loading) {
		loading = true;
		var optionsListDivID = 'options_list_'+newsItemID;
		var loaderID = 'loader_'+newsItemID;
		var triggerID = 'view_image_detail';
		var updateNodeId = 'newsdata';
		var url = '/getnewsitemimage/' + newsItemID + ".html";
		var ajaxUpdater = new Ajax.Updater(
			updateNodeId,
			url,
			{
				method:'get',
				onSuccess: function () {
					$(optionsListDivID).removeChild(loadingImage);
				}
			}
		);
		var my_tooltip_1 = new Tooltip(triggerID, updateNodeId);
		Effect.Appear(updateNodeId);
	}
 }
 
 /**
  * This method makes an ajax call to the server
  * in an effort to retrieve information about a news item
  */
function getNewsData(newsItemID) {

	if(false == loading) {
		loading = true;
		var optionsListDivID = 'options_list_' + newsItemID;
		var loaderID = 'loader_'+newsItemID;
		var triggerID = 'view_detail_'+newsItemID;
		var url = '/getnewsitem/' + newsItemID  + ".html";
		/*
		var loadingImage = new Element( 
			'img',
			{
				'id': loaderID,
				'src':'/includes/skin/default/images/ajax-loader.gif'
			}
		);
		
		$(optionsListDivID).appendChild(loadingImage);
		
		loadingImage.show();
		*/
		var ajaxUpdater = new Ajax.Updater(
			'newsdata',
			url,
			{
				method:'get',
				onSuccess: function () {
					$(optionsListDivID).removeChild(loadingImage);
				}
			}
		);
		var my_tooltip_1 = new Tooltip(triggerID, 'newsdata');
		Effect.Appear('newsdata');
	}
}

/**
 * This is a replacement generic function for the above functions that retrieve 
 * a particulcar attribute of an entity.
 * @param {Object} url
 * @param {Object} updateNode
 */
function getEntityData(urlString, updateNodeId, entityID) {
	if(false == loading) {
		
		loading = true;
		var triggerID = 'view_image_' + entityID;

		var ajaxUpdater = new Ajax.Updater(
			updateNodeId,
			urlString,
			{
				method:'get',
				onSuccess: function () {
					loading = false;
				}
			}
		);
		var my_tooltip_1 = new Tooltip(triggerID, updateNodeId);
		Effect.Appear(updateNodeId);
	}
}


/**
 * This function makes an async call to the server in order 
 * to expire the current user session record in the database.
 */
function setSessionExpired(sessionId) {
	var url = "/killsession/"+sessionId;
	var ajaxUpdater = new Ajax.Updater(
		'session_info',
		url,
		{
			method:'get',
			onSuccess: function () {
				//$(optionsListDivID).removeChild(loadingImage);
			}
		}
	);
}

/**
  * Remove the content of the tooltip
  */
function hideToolTip() {
		$('newsdata').innerHTML = '';
		loading = false;
}

/**
  * Remove the content of the tooltip
  */
function hideToolTipData(nodeID) {
		$(nodeID).innerHTML = '';
		loading = false;
}

/**
  * Create the draggable list 
  */
function registerSortable() {
	Sortable.create(
	"newslist",
	    { 
	    	dropOnEmpty:true,
	    	containment:["newslist"],
	    	constraint:false
	    }
	);
}

/**
  * This method moves all the selected items from one select list 
  * to another. 
  */
function swapSelected( fromID, toID ) {
	$A( $( fromID ).options ).each( function( elem ) {
		// if the user has selected the item remove and insert 
		// into the other list
		if(elem.selected) {
			$( toID ).insert( elem );
		}
	});
} 

/**
  * Show an alert for confirmation
  */
function confirmRequest() {
	var msg = "Alert: This action cannot be undone";
	msg = msg + "\n_____________________________\n\n";
	msg = msg + "Please confirm your request.";
	return confirm(msg);
}


/**
 * 
 * @param {Object} url
 * @param {Object} updateNode
 */
function addToHomePage(url, updateNode) {

	var ajaxRequest = new Ajax.Request(
		updateNode,
		url,
		{
			method:'post',
			onSuccess: function () {
				
			}
		}
	);
}






 