function scheduleDate(value,id)
{	
    	var timestamp = Date.parse(value);
    	var currentDate = new Date();
    	var hour = currentDate.getHours();
    	var min = currentDate.getMinutes();
    	currentDate.setTime(timestamp);
    	currentDate.setHours(hour);
    	currentDate.setMinutes(min);
    	timestamp = currentDate.getTime();
    	timestamp = timestamp/1000;
    	// get the current section
    	var section = 'day';
    	var matches = window.location.href.match(/\/section\/([^\/]*)/i);
    	if(matches && matches.length > 1) 
    		section = matches[1];
    	window.location = "/calendar/view-calendar/section/"+section+"/id/" + id + "/ts/" + timestamp;
}

var Calendar = {
	selectLinkType: function(elem, lid) {
		// get current table line
		var codes = eval('htmlCodes'+lid);
		try {
			var selectValue = dijit.byId('publicCalendarURLType_'+lid).value;
		} catch (e) {
			var selectValue = dojo.byId('publicCalendarURLType_'+lid).value
		}
		
		if(codes) {
			try { dojo.attr('htmlCode_'+lid,'innerHTML', unescape(codes[selectValue])); }
			catch (e) {
				dojo.attr('htmlCode_'+lid,'value', unescape(codes[selectValue])); 
			}
			dojo.attr('sampleArea_'+lid, 'innerHTML', unescape(codes[selectValue]).replace(/src=["']http[s]*:\/\/[^\/]+/i,'src="'));
		}
	},
	bulkChangeLinkTypes: function(linkType) {
		console.log(linkType);
		dojo.query('.listTable tbody tr').forEach(function(trElem){
			// get the checkbox
			console.log(dojo.query('input[type=checkbox]', trElem));
			var checkbox = dojo.query('input[type=checkbox]', trElem)[0];
			if(dojo.attr(checkbox,'checked')) {
				try {
					dijit.byId('publicCalendarURLType_'+checkbox.value).attr('value', linkType);
				} catch (e) {
					dojo.byId('publicCalendarURLType_'+checkbox.value).value = linkType;
					Calendar.selectLinkType(dojo.byId('publicCalendarURLType_'+checkbox.value),checkbox.value);
//					dojo.attr('publicCalendarURLType_'+checkbox.value, 'value', linkType);
				}
			}
		});
	},
	cleanupIdenticalApps: function() {
		dojo.query("[href*=appt-review]","calendarTable").forEach(function(node){
		    var match = node.href.match(/appt-review\/id\/[0-9]+/i);
		    if(match && match.length > 0) {
		        var similarNodes = dojo.query("[href*="+match[0]+"]","calendarTable");
		        var i = 0;
		        dojo.forEach(similarNodes, function(node1){
		            var parentTd = getElementParent(node1,'TD');
		            if(i!=0) dojo.style(node1,'display','none');
		            // remove the link's href if the underlying TD has onClick
		            var onTdClick = dojo.attr(parentTd,'onClick');
		            
		            if(onTdClick) {
		            	node1.href = 'javascript:void(0);';
		            }
		            if(i < similarNodes.length-1) {
		                dojo.addClass(parentTd,'noBottomBorder');
		            } else {
		                dojo.addClass(parentTd,'noTopBorder');
		            }
		            // check for overlapping
		            if(dojo.query('a',parentTd).length > 1) {
		                dojo.addClass(parentTd,'overlapApp');
		            }
		            i++;
		        });
		    }
		});
	},
	resizeSSForm: function() {
	    Calendar.setSSFormSize();
	    
	    dojo.query(".minimize").connect("onclick", 
		function(){
		    Calendar.setSSFormSize();
		}
	    );
	},
	setSSFormSize: function() {
	    var cont = dojo.byId('rfcont');
	    var contl = dojo.byId('rfcontl');
	    var ltable = dojo.byId('mainForm_section_3_0');
	    var height = dojo.style(contl,'height') + dojo.style(ltable,'height') + 100;
	    dojo.style(cont,'height',height+'px');
	},
	afterContactSearch: function() {
		Contacts.addAutoCompleteSearch('sellerSelect');
		Contacts.addAutoCompleteSearch('sellerFirstName');
		Contacts.addAutoCompleteSearch('sellerContactGroup');
		Contacts.addAutoCompleteSearch('sellerPhoneNumber');
		Contacts.addAutoCompleteSearch('sellerEmail');
	}
};

var Appointments = {
	changeType: function(select, defaultShowingTypeName, showingTypeOptionsElementIds, reminderLabelDisplayName) {
		if (reminderLabelDisplayName[select.attr("value")] != undefined) {
			dojo.byId('appointment_remindPriorContact_label').innerHTML = reminderLabelDisplayName[select.attr("value")];
		} else {
			dojo.byId('appointment_remindPriorContact_label').innerHTML = 'Other';
		}
		if(select.attr("value") == defaultShowingTypeName) {
			//console.log('Must show element options');
			for(elId in showingTypeOptionsElementIds) {
				show(showingTypeOptionsElementIds[elId]);
			}
		} else {
			//console.log('Must hide showing type other options');
			for(elId in showingTypeOptionsElementIds) {
				hide(showingTypeOptionsElementIds[elId]);
			}
		}
	}
};
