// JavaScript Document

function clearText(field) {
	if (field.defaultValue == field.value) field.value = '';
	else if (field.value == '') field.value = field.defaultValue;
}

function copyRecipients(field) {
	var fieldval = field.value;
		
	fieldval = fieldval.stripTags();
	fieldval = fieldval.replace(/\(x\)/gi, "");
	
	document.getElementById('recipients').value = document.getElementById('recipients').value + fieldval; 
	document.getElementById('recipient').selectedIndex = 0; 
}

function clearRecipients() {

	document.getElementById('recipients').value = "";

}

function create_picture_input(field) {
	if (field.value != '') {
		
		var new_field_name = Math.floor(Math.random()*1001);
		while (!document.getElementsByTagName(new_field_name)) {
			new_field_name = Math.floor(Math.random()*1001);
		}
		
		var html = '<input type="file" name="'+new_field_name+'" onchange="create_picture_input(this); return false;" />';
		new Insertion.Bottom($('picture_inputs'), html);
		
	}
}

function attending_rollout() {
	if ($('attending_rollout').getStyle('display') == 'none') {
		$('notattending_rollout').setStyle({display: 'none'});
		if ($('attending_rollout')) {
			$('attending_rollout').setStyle({display: 'block'});
		}
	}
}
function notattending_rollout() {
	if ($('notattending_rollout').getStyle('display') == 'none') {
		if ($('attending_rollout')) {
			$('attending_rollout').setStyle({display: 'none'});
		}
		$('notattending_rollout').setStyle({display: 'block'});
	}
}

function create_time_input(field) {
	if (field.value != '') {
		
		var new_field_name = Math.floor(Math.random()*1001);
		while (!document.getElementsByTagName(new_field_name)) {
			new_field_name = Math.floor(Math.random()*1001);
		}
		
		var html = '\
		<div style="margin-top:10px;">\
		<div style="width:100px; float:left;">Start Time:</div>\
		<input type="text" name="sh_'+new_field_name+'" style="width:20px;" maxlength="2" />:<input type="text" name="sm_'+new_field_name+'" maxlength="2" style="width:20px;" />\
		<select name="sap_'+new_field_name+'">\
			<option value="AM" >AM</option>\
			<option value="PM" selected>PM</option>\
		</select> \
		hh:mm am/pm\
		<br />\
		<div style="width:100px; float:left;">End Time:</div>\
		<input type="text" name="eh_'+new_field_name+'" style="width:20px;" maxlength="2" />:<input type="text" name="em_'+new_field_name+'" maxlength="2" style="width:20px;" />\
		<select name="eap_'+new_field_name+'">\
			<option value="AM" >AM</option>\
			<option value="PM" selected>PM</option>\
		</select> \
		hh:mm am/pm\
		</div>\
		';
		new Insertion.Bottom($('time_inputs'), html);
		
	}
}