// -- start init (and supporting functions) {{{
function init(){
	var startDate = $("keyStartDate");
	if (startDate){
		startDate.value = get_start_date();
	}
		
	insert_datepicker_iframe();
}

function get_start_date(){
	// set start date to today
	var d = new Date();

	//append a zero to months and dates with only one digit
	d = [d.getMonth() + 1, d.getDate(), d.getFullYear()].collect(function(x){
		if (x < 10){
			x = "0" + x;
		}
		return x;
	});

	return d.join('/');
}

function insert_datepicker_iframe(){
	var iframe = '<iframe width="132" height="142" name="gToday:contrast:agenda.js" id="gToday:contrast:agenda.js" src="calendar/ipopeng.htm" scrolling="no" frameborder="0" style="visibility:visible; z-index:999; position:absolute; left:-500px; top:0px;"></iframe>'
	new Insertion.Bottom(document.body, iframe);
}

function go(){
	var cX = ['t:8//:ssl//sitemap taxonomy//:Calendar:'];

	// user query
	var query = $("keyPhrase");
	if (query && query.value != ""){
		$('command').value = "text";
		$('attr1').value = query.value;
	}

	// start date and end date constraint
	get_start_and_end_date("keyStartDate", "keyEndDate").each(function(d){
		cX.push(d);
	});

	FORM_SECTIONS.each(function(section){
		var group_class = section[0];
		var checked_values = get_checked_values(group_class);
		if (checked_values.length != 0) {
			if (group_class == 'siteString') {
				checked_values.each(function(v){v = "s:8;" + group_class + ";:ss;" + v;});
				cX.push(checked_values.join('.'));
			}else{
				cX.push("e:8//" + group_class + "//:in//" + checked_values.join(','));
			}
		}
	});

	// push to form and disable unused
	for (var i=0; i < 7; i++){
		if (cX[i]) {
			$('c' + i).value = cX[i];
		}else{
			$('c' + i).disabled = true;
		}
	}

	$('search').submit();
}