
function timeInputFields ( inTime, prefix ) {
	
	var time = new Date ( inTime * 1000 );
	
	var hour = new Element("input", { 'value' : '00', 'onChange' : "validateTime(this, 'hour'); clearValidationResponse(); ", 'size' : '2', 'name' : prefix+'_hour', 'class' : 'formInput', 'id' : prefix+'_hour' } );
	var min = new Element("input", { 'value' : '00', 'onChange' : "validateTime(this, 'min'); clearValidationResponse(); ", 'size' : '2', 'name' : prefix+'_min', 'class' : 'formInput', 'id' : prefix+'_min' } );
	var ampm = new Element("select", { 'onChange' : "validateTime(this, 'ampm'); clearValidationResponse(); ", 'name' : prefix+'_ampm', 'class' : 'formInput', 'id' : prefix+'_ampm' } );
	ampm.insert("<option>AM</option>");
	ampm.insert("<option>PM</option>");
	
	var s = $(prefix+"_time_fields");
	s.update(hour);
	s.insert(":");
	s.insert(min);
	s.insert(" ");
	s.insert(ampm);
		
}

function showCalendar ( callerID, time, link ) {
	document.getElementById( callerID ).src="/web/template/images/icon/expand_minus.png";
	reloadCalendar( callerID, time, link );
}

function validateTime ( input, bit ) {
	
	if ( bit == 'hour' ) {
		if ( ! ( $(input).value > 0 && $(input).value < 13 ) ) {
			$(input).value=12;	
			new Effect.Highlight(input, { startcolor: '#ff0000',
				endcolor: '#ffffff' });
		}
	} else if ( bit == 'min' ) {
		if ( ! ( $(input).value > -1 && $(input).value < 60 ) ) {
			$(input).value='00';
			new Effect.Highlight(input, { startcolor: '#ff0000',
				endcolor: '#ffffff' });
			
		} else if ( $(input).value == 0 ) {
			$(input).value = '00';
		}
			
	}
	
}

function highlightDiv ( element ) {
	$(element).setStyle({'background' : '#eee', 'cursor' : 'pointer'});
}

function restoreDiv ( element ) {
	$(element).setStyle({'background' : 'none', 'cursor' : 'default'});
}

function setTimeFromDate( day, month, year ) {
	
	var dDate = new Date();
	//console.log(targetid + day.value + month.value + year.value );
	dDate.setMonth(month.value,day.value);
	dDate.setFullYear(year.value);
	dDate.setHours("0","0","0");
	return (dDate.getTime()-dDate.getMilliseconds())/1000;

}

function addRecipientToList ( source ) {
	
	if ( $(source).value != null ) {
		$('recipientlist').insert($(source).value+', ');
	}
}

function doLogin ( form  ) {
	
	var serverPage = '/web/services/login.php?login='+$('login').value+'&password='+$('password').value;
	//console.log( "function.js->doLogin(): " +serverPage );
	$(form).innerHTML="Logging in..";
	new Ajax.Request(serverPage, {
		method: 'get',
		onSuccess: function(thepage) {
			var Error = thepage.responseText;
		}
	});
}



function getareas ( venue_id, selected_id ) {

	var serverPage = "/web/services/dd_venuearea.inc.php?venue_id=" + venue_id + "&selected_id=" + selected_id;
	new Ajax.Request(serverPage, {
		method: 'get',
		onSuccess: function(thepage) {
			$("venue_area").update(thepage.responseText);
		}
	});
}




function setLocation ( str ) {

	$('location').value=str;
	//$('location_menu').setStyle({'visibility' : 'hidden' });
	
}

function getUserProfileTypes ( populate ) {
	var serverPage 	= "/web/services/view/dd_type.inc.php"
	new Ajax.Request(serverPage, {
		onSuccess: function(thepage) {
		$(populate).insert( thepage.responseText );
		}
	});
}


function getUserType ( typeID, callerID, selectedID ) {
	
	var serverPage 	= "/web/services/view/dd_typeid.inc.php?type=" + typeID + "&selected=" + selectedID;
	new Ajax.Request(serverPage, {
		onSuccess: function(thepage) {
			$(callerID).update( thepage.responseText );
		}
	});
	
}

function getartistlist ( user_id, populateID ) {
	
	var startStr = $('start_hour').value+':'+$('start_min').value+$('start_ampm').options[$('start_ampm').selectedIndex].text;
	var finishStr = $('finish_hour').value+':'+$('finish_min').value+$('finish_ampm').options[$('finish_ampm').selectedIndex].text;
	var serverPage 	= "/web/services/view/dd_artist.inc.php?user_id="+user_id+"&available="+$('showavailableartistonly').checked+"&start="+startStr+"&finish="+finishStr+"&date="+$('fromDate').value;
	
	new Ajax.Request(serverPage, {
		method: 'get',
		onSuccess: function(thepage) {
			$(populateID).update( thepage.responseText );
		}
	});
}

function getvenues ( user_id, agent_id, selected_id ) {

	var serverPage 	= "/web/services/view/dd_venue.inc.php?user_id=" + user_id + "&agent_id=" + agent_id + "&selected_id=" + selected_id;
	new Ajax.Request(serverPage, {
		method: 'get',
		onSuccess: function(thepage) {
			$("venue_menu").update(thepage.responseText);
		}
	});
}

function openprofile(userid) {
	window.open('/web/common/userProfile.inc.php?id='+userid,'popup','width=400,height=400');
}

function reloadCalendar ( callerID, time, target ) {

	var serverPage = "/web/common/calendar.inc.php?id=" + callerID + "&t=" + time +"&target=" + target;
	new Ajax.Request(serverPage, {
		method: 'get',
		onSuccess: function(thepage) {
			var a	= new Element('div').update(thepage.responseText);
			$(callerID + "Calendar").update( a );
		}
	});	
}





function setRowAsChanged( callerID ) {

	var color = "#f4dcc5";
	//console.log(Object.inspect(callerID));
	if ( callerID != '' ) {
		$(callerID).up('tr').setStyle({'background':color});
	} else {
		console.log("Empty row received " + callerID);
	}
	
}






function showLoader ( target ) {
	var a = new Element('div');
	$(target).update( a.update('<img src="/web/template/images/icon/spinner.gif" />') );
}
function showProcessor ( target ) {
	var a = new Element('div');
	$(target).update( a.update('<img src="/web/template/images/icon/processing.gif" />') );
}



function viewDate ( time ) {
	
	var serverPage 	= "/web/services/view/date.inc.php?view=" + time;
	new Ajax.Request(serverPage, {
		method: 'get',
		onSuccess: function(thepage) {
			$('viewDate').update(thepage.responseText);
		}
	});
}