var cal_w = null;
var s = null;
function init_cdt_widget()
{
	//cal_w = new Calendar({adate: '%D %F %d, %Y'}, {classes: ['dashboard'], direction: 1, draggable: false, onHideComplete: function(){}});
	cal_w = new CalendarEightysix('adate', {'format': '%a %b %d, %Y', 'disallowUserInput': true, 'toggler': 'coi'});
}
function make_cdt_widget()
{
	var date = $('adate');
	var time = $('atime');
	var size = $('size');
	if (date == null || time == null || size == null)
	{
		alert('An error occured, please reload the page.');
		return;
	}
	if (date.value == '')
	{
		alert('You should at least set a date for the widget to work!');
		return;
	}
	// alert(cal_w.selectedDate);
	var d = cal_w.selectedDate.getFullYear() + '-' + (cal_w.selectedDate.getMonth() + 1) + '-' + cal_w.selectedDate.getDate();
	//
	show_widget_box();
	var json = new Request.JSON({url: '/widgets/setup-countdown/', urlEncoded: true, onSuccess: function(rj, rt){
		if (rj.error != '')
		{
			alert(rj.error);
		}
		else
		{
			var css = 'mh_cdt_s';
			var br = '<br />';
			if (parseInt(size.get('value')) == 210)
			{
				css = 'mh_cdt_h';
				br = '';
			}
			var str = '';
			wp = '<div id="mh_cdt" class="' + css + '"><p id="mh_cdt_p">I will be in Mykonos in <span id="c_mh_cdt"></span></p><span class="pr">Widget provided by ' + br + '<a href="http://www.mykonos-hotels.info/" target="_blank" id="mh_cdt_a">Mykonos Hotels</a></span></div>';
			wc = '<div id="mh_cdt" class="' + css + '"><p id="mh_cdt_p">I will be in Mykonos in <span id="c_mh_cdt"></span></p><span class="pr">Widget provided by ' + br + '<a href="http://www.mykonos-hotels.info/" target="_blank" id="mh_cdt_a">Mykonos Hotels</a></span>&lt;script type="text/javascript" src="http://www.mykonos-hotels.info/widgets/countdown/' + rj.t + '/"&gt;&lt;/scr' + 'ipt&gt;</div>';
			str = '<p>This is how your widget will display on your pages.</p>' + wp + '<p>Copy the code below and paste it to the webpage ' + br + ' you want the widget to appear.</p><textarea name="w" cols="55" rows="7" style="font-size: 11px;">' + wc + '</textarea>';
			//str = '<p>Copy the code below and paste it to the webpage ' + br + ' you want the widget to appear.</p><textarea name="w" cols="55" rows="7" style="font-size: 11px;">' + wc + '</textarea>';
			$('widget_box').set('html', str);
			if (typeof(mh_ctd_timer) != 'undefined') clearTimeout(mh_ctd_timer);
			s = new Element('script', {type: 'text/javascript', src: '/widgets/countdown/' + rj.t + '/1/'});
			document.getElementsByTagName("head")[0].appendChild(s);
		}
	}}).send('d=' + d + '&t=' + time.value + '&s=' + size.get('value'));
}
function show_widget_box()
{
	$('widget_box').set('html', 'Please wait...');
}
