var gotourl = false;

function open_datepicker(return_id,open_id,my_gotourl)
{
	gotourl = ( !my_gotourl ? false : true);

	//
	// Get all selctboxes and hide 'em (IE z-index bug)
	arr_select = document.getElementsByTagName('select');
	for(var i = 0; i<arr_select.length; i++)
	{
		arr_select[i].style.visibility = 'hidden';
	}
	
	$(open_id).style.display = 'block';
	var date = $(return_id).value;
	new Ajax.Updater(
					$(open_id),
					globalModule + 'datepicker/ajax.display.month.php', {
					method: 'post',
					parameters: 'open_id=' + open_id + '&return_id=' + return_id + '&date=' + date,
					asynchronous: true}
					);
}

/**
* Used when quickpicking (using the selectboxes) to display a specific month
* - Kinda initialiser, reads data fra form then calls for display of month
* 
* @param None
* @return None Calling dp_display_month() to display month
*/
function dp_quickpick()
{
	var date = $('qp_year').value + '-' + $('qp_month').value + '-1 ' + $('dp_hour').value + ':' + $('dp_minute').value + ':' + $('dp_second').value;
	dp_display_month(date);
}

/**
* Displays specific month from Ajax call
* 
* @param String $date Specific date (month) to show
* @return Mixed Ajax updater datepicker
*/
function dp_display_month(date)
{
	var open_id			= $('open_id_container').value;
	var return_id		= $('return_id_container').value;

	new Ajax.Updater(
					$(open_id),
					globalModule + 'datepicker/ajax.display.month.php', {
					method: 'post',
					parameters: 'open_id=' + open_id + '&return_id=' + return_id + '&date=' + date,
					asynchronous: true}
					);
}

/**
* Show and returns date to calle-form, when date is picked, closing the Modal Window
* - The windw object is stored in _global globalWin Array
* - The Elements we wanna return data to is stored in _global globalWinReturn
* - NOTE! QUICKFIX. The Human readable display date is returned to an element w/ id='display_' + id of the open_id (display_ is a prefix...)
* 
* @param String $date Date to return wo/ time
* @param String $display_date More human readable date
* @return String Updates element calling the datepicker
*/
function dp_return_date(date,display_date,gotoyear,gotoweek,redirectUrl)
{
	var open_id		= $('open_id_container').value;
	var return_id	= $('return_id_container').value;
	
	//date	= date + ' ' + $('dp_hour').value + ':' + $('dp_minute').value + ':' + $('dp_second').value;
	$(return_id).value = date;
	$(open_id).innerHTML		= '';
	$(open_id).style.display	= 'none';

	$('display_' + open_id).innerHTML	= display_date;

	//
	// Get all selctboxes and hide 'em (IE z-index bug)
	arr_select = document.getElementsByTagName('select');
	for(var i = 0; i<arr_select.length; i++)
	{
		arr_select[i].style.visibility = 'visible';
	}

    if (open_id.indexOf('meeting') != -1 &&
        window.show_meeting_timetable)
    {
        show_meeting_timetable();
    }
    else if (open_id.indexOf('phone') != -1 &&
        window.show_phone_timetable)
    {
        show_phone_timetable();
    }
    else if (open_id.indexOf('dyslexic') != -1 &&
        window.show_dyslexic_timetable)
    {
        show_dyslexic_timetable();
    }

	if(gotourl === true)
	{
		if (window.base_goto_url)
		{
			window.location.href	= window.base_goto_url + gotoyear + '/' + gotoweek;
		}
		else
		{
			window.location.href	= globalBooking + 'timetable/view/all/' + gotoyear + '/' + gotoweek;
		}
	}
}

function dp_close_datepicker()
{
	var open_id		= $('open_id_container').value;
	$(open_id).style.display = 'none';
	$(open_id).innerHTML		= '';

	//
	// Get all selctboxes and hide 'em (IE z-index bug)
	arr_select = document.getElementsByTagName('select');
	for(var i = 0; i<arr_select.length; i++)
	{
		arr_select[i].style.visibility = 'visible';
	}
}
