/**
* Proxy script to fetch openning hours from Gentofte, called by ajax
* to prevent locked on javascript menus if Gentofte script is slow or contains errors
*
* @author    Michael Isaksen <isaksen@open.dk>
* @copyright InleadMedia
* @package   Easysite
* @since     Easysite 4.0
*/

/**
* Call our .php proxy script through Ajax 
* (the html page with openning hours fetched from Gentofte server) 
*
* @author  Michael Isaksen <isaksen@open.dk>
*
* @param   string datechg  'f|b' controls the forward backward arrows
* @param   String viewDate The Date to view -1 day
* @return  void void
*/
function getOpeningAjax(datechg, viewDate)
{
	// if first run
	if (datechg == null) 
	{
		var datechg = '';
	}

	// if first run
	if (viewDate  == null) 
	{
  	var now = new Date();
  	var y =  now.getFullYear();
  	var m =  now.getMonth()+1;
  	var d =  now.getUTCDate();
 	  var viewDate = d+'-'+m+'-'+y; 
	}

	// fetch the opening hours from Gentofte through our proxy script
	new Ajax.Request('openinghours.php', { // url to the possible slow script
				method: 'post',
				parameters: 'datechg=' + datechg + '&viewDate=' + viewDate,
				onComplete: showResponse
			});
}

/**
* Event handler for function getOpeningAjax reponse
* assigns the response, if valid, to innerHtml
*
* @author  Michael Isaksen <isaksen@open.dk>
*
* @param   Object request Object from ajax
* @return  void void
*/
function showResponse(request) 
{
	//alert(request.responseText);
	// only substitute the innerHtml if we get a valid response from Gentofte script
	if (request.responseText.indexOf("viewdate") > 0) 
	{
		$('openingHours').innerHTML = request.responseText;
	}
} 