// core.js

// Formfield Definitions

/*
Field Types:
1: text-line 			-required: field_label
2: text-box 			-required: field_label
3: checkbox 			-required: field_label, return_value
4: radio-buttons		-required: field_label, field_options (new Array('val1','val2','...')), free_attributes (new Array('attr1','attr2','...')) !!! number of elements FREE_ATTRIBUTES must equal number of elements FIELD_OPTIONS !!!
5: date-field 			-required: field_label
6: date/time-field 		-required: field_label, free_attributes (new Array('date-button attr','time-button attr')) !!! number of elements FREE_ATTRIBUTES must be TWO(2) !!!
7: drop-down 			-required: field_label, field_options (new Array('val1','val2','...')), free_attributes (new Array('drop-down attr','attr val1','attr val2','...')) !!! number of elements FREE_ATTRIBUTES must equal number of elements FIELD_OPTIONS + 1 !!!
8: check all applicable	-required: field_label, field_options (new Array('val1','val2','...')), free_attributes (new Array('attr1','attr2','...')) !!! number of elements FREE_ATTRIBUTES must equal number of elements FIELD_OPTIONS !!!
9: hidden 				-required: field_label, return_value
10: comment/instruction	-required: field_label
11: e-mail address		-required: field_label, free_attributes (new Array('attr1','attr2')) !!! number of elements FREE_ATTRIBUTES must be TWO(2) !!!
12: password			-required: field_label, free_attributes (new Array('attr1','attr2')) !!! number of elements FREE_ATTRIBUTES must be TWO(2) !!!
13: read-only			-required: field_label, free_attributes (new Array('id="[field_id]")) !!! FREE_ATTRIBUTES must contain element id !!!
13: file				-required: field_label

// Sample Array

field_type[index]		=	1;
field_label[index]		=	'text-line';
db_label[index]			=	'';
linebreak[index]		=	0;
field_size[index]		=	'';
field_rows[index]		=	'';
field_options[index]	=	new Array();
return_value[index]		=	'';
prefill_value[index]	=	new Array('');
prefill_date[index]		=	'';
prefill_time[index]		=	'';
permitted_chars[index]	=	' abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890,\'":;,/?!$%&()-+=';
required[index]			=	1;
flagged[index]			=	1;
free_attributes[index]	=	new Array('onkeyup="getElementById(\'value_display\').value=this.value;"');
index++;

field_type[index]		=	2;
field_label[index]		=	'text-box';
db_label[index]			=	'';
linebreak[index]		=	0;
field_size[index]		=	'30';
field_rows[index]		=	'5';
field_options[index]	=	new Array();
return_value[index]		=	'';
prefill_value[index]	=	new Array('');
prefill_date[index]		=	'';
prefill_time[index]		=	'';
permitted_chars[index]	=	' abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890,\'":;,/?!$%&()-+=';
required[index]			=	1;
flagged[index]			=	0;
free_attributes[index]	=	new Array('');
index++;

field_type[index]		=	3;
field_label[index]		=	'checkbox';
db_label[index]			=	'';
linebreak[index]		=	1;
field_size[index]		=	'';
field_rows[index]		=	'';
field_options[index]	=	new Array();
return_value[index]		=	'selected';
prefill_value[index]	=	new Array('1');
prefill_date[index]		=	'';
prefill_time[index]		=	'';
permitted_chars[index]	=	'';
required[index]			=	1;
flagged[index]			=	0;
free_attributes[index]	=	new Array('');
index++;

field_type[index]		=	4;
field_label[index]		=	'radio button';
db_label[index]			=	'';
linebreak[index]		=	0;
field_size[index]		=	'';
field_rows[index]		=	'';
field_options[index]	=	new Array('Yes','No','Who knows?');
return_value[index]		=	'';
prefill_value[index]	=	new Array('','1','');
prefill_date[index]		=	'';
prefill_time[index]		=	'';
permitted_chars[index]	=	'';
required[index]			=	1;
flagged[index]			=	0;
free_attributes[index]	=	new Array('','','');
index++;

field_type[index]		=	5;
field_label[index]		=	'date';
db_label[index]			=	'';
linebreak[index]		=	0;
field_size[index]		=	'';
field_rows[index]		=	'';
field_options[index]	=	new Array();
return_value[index]		=	'';
prefill_value[index]	=	new Array('');
prefill_date[index]		=	'';
prefill_time[index]		=	'';
permitted_chars[index]	=	'';
required[index]			=	1;
flagged[index]			=	0;
free_attributes[index]	=	new Array('');
index++;

field_type[index]		=	6;
field_label[index]		=	'date and time';
db_label[index]			=	'';
linebreak[index]		=	1;
field_size[index]		=	'';
field_rows[index]		=	'';
field_options[index]	=	new Array();
return_value[index]		=	'';
prefill_value[index]	=	new Array('');
prefill_date[index]		=	'';
prefill_time[index]		=	'';
permitted_chars[index]	=	'';
required[index]			=	1;
flagged[index]			=	0;
free_attributes[index]	=	new Array('');
index++;

field_type[index]		=	7;
field_label[index]		=	'dropdown list';
db_label[index]			=	'';
linebreak[index]		=	0;
field_size[index]		=	'';
field_rows[index]		=	'';
field_options[index]	=	new Array('Yes','No','Who knows?');
return_value[index]		=	'';
prefill_value[index]	=	new Array('1','','');
prefill_date[index]		=	'';
prefill_time[index]		=	'';
permitted_chars[index]	=	'';
required[index]			=	1;
flagged[index]			=	0;
free_attributes[index]	=	new Array('','','');
index++;

field_type[index]		=	8;
field_label[index]		=	'Check all that apply';
db_label[index]			=	'';
linebreak[index]		=	0;
field_size[index]		=	'';
field_rows[index]		=	'';
field_options[index]	=	new Array('Yes','No','Who knows?');
return_value[index]		=	'';
prefill_value[index]	=	new Array('1','1','1');
prefill_date[index]		=	'';
prefill_time[index]		=	'';
permitted_chars[index]	=	'';
required[index]			=	1;
flagged[index]			=	0;
free_attributes[index]	=	new Array('','','');
index++;

field_type[index]		=	9;
field_label[index]		=	'hidden';
db_label[index]			=	'';
linebreak[index]		=	0;
field_size[index]		=	'';
field_rows[index]		=	'';
field_options[index]	=	new Array();
return_value[index]		=	'This was sent by a form';
prefill_value[index]	=	new Array('');
prefill_date[index]		=	'';
prefill_time[index]		=	'';
permitted_chars[index]	=	'';
required[index]			=	1;
flagged[index]			=	0;
free_attributes[index]	=	new Array('');
index++;

field_type[index]		=	10;
field_label[index]		=	'comment/instruction';
db_label[index]			=	'';
linebreak[index]		=	0;
field_size[index]		=	'';
field_rows[index]		=	'';
field_options[index]	=	new Array();
return_value[index]		=	'';
prefill_value[index]	=	new Array('');
prefill_date[index]		=	'';
prefill_time[index]		=	'';
permitted_chars[index]	=	'';
required[index]			=	0;
flagged[index]			=	0;
free_attributes[index]	=	new Array('');
index++;

field_type[index]		=	11;
field_label[index]		=	'e-mail address';
db_label[index]			=	'';
linebreak[index]		=	0;
field_size[index]		=	'';
field_rows[index]		=	'';
field_options[index]	=	new Array('Yes','No');
return_value[index]		=	'';
prefill_value[index]	=	new Array('');
prefill_date[index]		=	'';
prefill_time[index]		=	'';
permitted_chars[index]	=	'';
required[index]			=	1;
flagged[index]			=	0;
free_attributes[index]	=	new Array('','');
index++;

field_type[index]		=	12;
field_label[index]		=	'password';
db_label[index]			=	'';
linebreak[index]		=	1;
field_size[index]		=	'';
field_rows[index]		=	'';
field_options[index]	=	new Array('Yes','No');
return_value[index]		=	'';
prefill_value[index]	=	new Array('');
prefill_date[index]		=	'';
prefill_time[index]		=	'';
permitted_chars[index]	=	'';
required[index]			=	1;
flagged[index]			=	0;
free_attributes[index]	=	new Array('','');
index++;

field_type[index]		=	13;
field_label[index]		=	'read only';
db_label[index]			=	'';
linebreak[index]		=	0;
field_size[index]		=	'30';
field_rows[index]		=	'';
field_options[index]	=	new Array();
return_value[index]		=	'';
prefill_value[index]	=	new Array('copied from first field');
prefill_date[index]		=	'';
prefill_time[index]		=	'';
permitted_chars[index]	=	'';
required[index]			=	0;
flagged[index]			=	1;
free_attributes[index]	=	new Array('id="value_display" style="background-color:red;"');
index++;

field_type[index]		=	14;
field_label[index]		=	'file';
db_label[index]			=	'';
linebreak[index]		=	0;
field_size[index]		=	'';
field_rows[index]		=	'';
field_options[index]	=	new Array();
return_value[index]		=	'';
prefill_value[index]	=	new Array('');
prefill_date[index]		=	'';
prefill_time[index]		=	'';
permitted_chars[index]	=	'';
required[index]			=	0;
flagged[index]			=	0;
free_attributes[index]	=	new Array('');
index++;





// Submit-Button
submitbutton_txt= 'Send!';
submit_button_id='submit_button'
submit_button_active=1;
*/

//=======================================================================//

var field_type=[];var field_label=[];var linebreak=[];var field_size=[];var field_rows=[];var field_options=[];var return_value=[];var prefill_date=[];var prefill_time=[];var permitted_chars=[];var required=[];var flagged=[];var db_label=[];free_attributes=[];prefill_value=[];
var calendar_count=0;
var index=0;

// Check Form
function checkForm(){
	var element_trace=0;
	for(field_count=0;field_count<field_type.length;field_count++){
		if(required[field_count]){
			if(field_type[field_count]==3){
				if(!document.jsForm.elements[element_trace].checked){report_missing(field_count,element_trace);return false;}
				element_trace++;
			}else if((field_type[field_count]==4)||(field_type[field_count]==9)){
					var checkmark_check=false;
					for(option_count=0;option_count<field_options[field_count].length;option_count++){
						if(document.jsForm.elements[element_trace].checked){checkmark_check=true;}
						element_trace++;
					}
				if(!checkmark_check){report_missing(field_count,element_trace);return false;}
			}else if(field_type[field_count]==8){
				if(document.jsForm.elements[element_trace].selectedIndex<2){report_missing(field_count,element_trace);return false;}
				element_trace++;
			}else if(field_type[field_count]==6){
				if((!document.jsForm.elements[element_trace].value.length) || (!document.jsForm.elements[element_trace+1].value.length)){report_missing(field_count,element_trace);return false;}
				element_trace+=2;
			}else{
				if(!document.jsForm.elements[element_trace].value.length){report_missing(field_count,element_trace);return false;}
				element_trace++;
				if((field_type[field_count]==5) || (field_type[field_count]==11) || (field_type[field_count]==12) || (field_type[field_count]==14)){
					element_trace++;
				}
			}
		}else{
			if((field_type[field_count]==4)||(field_type[field_count]==7)){
				element_trace+=field_options[field_count].length;
			}else if((field_type[field_count]==5) || (field_type[field_count]==11) || (field_type[field_count]==12) || (field_type[field_count]==14)){
				element_trace+=2;
			}else if(field_type[field_count]==6){
				element_trace+=3;
			}else{
				if(field_type[field_count]!=10){
					element_trace++;
				}
			}
		}
	}
	return true;
}
// Place focus and create alert
function report_missing(fc,et){
	document.jsForm.elements[et].focus();
	alert(field_label[fc] + " is required!");
}
// Check for illegal characters
function check_chars(entered,permitted,label){
	if(permitted.length){
		var detected='';
		for(x=0;x<entered.length;x++){
			for(y=0;y<permitted.length;y++){
				// search illegal
				if(permitted.indexOf(entered.charAt(x))<0){
					var illegal_char=entered.charAt(x);
					//remove illegal
					var buffer='';
					for(z=0;z<entered.length;z++){
						if(entered.charAt(z)!=illegal_char){
							buffer=buffer+entered.charAt(z);
						}
					}
					entered=buffer;
					detected = detected+ illegal_char;
				}else{
					// terminate inner loop
					y=permitted.length;
				}
			}
		}
		if(detected.length){
			alert(label.toUpperCase() + " contained the following illegal characters:\n' " + detected + " '\nAllowed are only the following characters:\n'" + permitted + "'\nNOTICE: ALL ILLEGAL CHARACTERS WILL BE REMOVED!");
		}
	}
	return entered;
}
// Create Form
function createForm(){
	var form_html='';
	var enctype='';

	for(field_count=0;field_count<field_type.length;field_count++){
		if((required[field_count]) && field_type[field_count]!=3){
			required_label='<span style="color:red;">*</span>';
		}else{
			required_label='';
		}
		if(flagged[field_count]){
			if(required_label.length){required_label=required_label+'/';}
			required_label=required_label+'<span style="color:red;">**</span>';
		}
		if(db_label[field_count]){
			var form_field_label=db_label[field_count];
		}else{
			var form_field_label=field_label[field_count];
		}
		//--- FORMFIELD TYPES ---
		// textline
		if(field_type[field_count]==1){
			form_html=form_html+'<td valign="top"><b>'+field_label[field_count]+required_label+'</b> <input type="text" name="'+form_field_label+'" size="'+field_size[field_count]+'" value="'+prefill_value[field_count][0]+'" onblur="this.value=check_chars(this.value,\''+permitted_chars[field_count]+'\',\''+field_label[field_count]+'\');" '+free_attributes[field_count][0]+' /></td>';
		}
		// textbox
		else if(field_type[field_count]==2){
			form_html=form_html+'<td valign="top"><b>'+field_label[field_count]+required_label+'</b><br /><textarea name="'+form_field_label+'" cols="'+field_size[field_count]+'" rows="'+field_rows[field_count]+'" onblur="this.value=check_chars(this.value,\''+permitted_chars[field_count]+'\',\''+field_label[field_count]+'\');" '+free_attributes[field_count][0]+'>'+prefill_value[field_count][0]+'</textarea></td>';
		}
		// checkbox
		else if(field_type[field_count]==3){
			if(prefill_value[field_count][0]){prefill_value[field_count][0]='checked="true"';}
			form_html=form_html+'<td valign="top"><table cellpadding="0" cellspacing="0" style="font-family:sans-serif;font-size:1.0em;"><tr><td><input type="checkbox" name="'+form_field_label+'" '+prefill_value[field_count][0]+' value="'+return_value[field_count]+'" '+free_attributes[field_count][0]+' /></td><td><b>'+field_label[field_count]+required_label+'</b></td></tr></table></td>';
		}
		// radio buttons
		else if(field_type[field_count]==4){
			form_html=form_html+'<td valign="top"><b>'+field_label[field_count]+required_label+'</b><table style="font-family:sans-serif;font-size:1.0em;">';
			for(option_count=0;option_count<field_options[field_count].length;option_count++){
				if(prefill_value[field_count][option_count]){prefill_value[field_count][option_count]='checked="true"';}
				form_html=form_html+'<tr><td><input type="radio" name="'+form_field_label+'" value="'+field_options[field_count][option_count]+'" '+prefill_value[field_count][option_count]+' '+free_attributes[field_count][option_count]+' /> </td><td>'+field_options[field_count][option_count]+'</td></tr>';
			}
			form_html=form_html+'</table></td>';
		}
		// date-field
		else if(field_type[field_count]==5){
			form_html=form_html+'<td valign="top"><table style="font-family:sans-serif;font-size:1.0em;" cellpadding="0" cellspacing="0"><tr><td><b>'+field_label[field_count]+required_label+'</b> <table cellpadding="0" cellspacing="0"><tr><td nowrap="true"><input type="text" name="'+form_field_label+'" id="'+field_label[field_count]+'" size="10" readonly="true" value="'+prefill_date[field_count]+'" onclick="form_calendar(\''+field_label[field_count]+'\',\'\',\'calendar'+calendar_count+'\',\''+prefill_date[field_count]+'\')" '+free_attributes[field_count][0]+' /><input type="button" value="[+]" onclick="form_calendar(\''+field_label[field_count]+'\',\'\',\'calendar'+calendar_count+'\',\''+prefill_date[field_count]+'\')" style="font-size:10px;" /></td></tr></table><div id="calendar'+calendar_count+'"></div></td></tr></table>';
			calendar_count++;
		}
		// date/time-field
		else if(field_type[field_count]==6){
			form_html=form_html+'<td valign="top"><table style="font-family:sans-serif;font-size:1.0em;" cellpadding="0" cellspacing="0"><tr><td><b>'+field_label[field_count]+required_label+'</b> <table cellpadding="0" cellspacing="0"><tr><td nowrap="true"><input type="text" name="'+form_field_label+'_date" id="'+field_label[field_count]+'_date" size="10" readonly="true" value="'+prefill_date[field_count]+'" onclick="form_calendar(\''+field_label[field_count]+'_date\',\''+field_label[field_count]+'_time\',\'calendar'+calendar_count+'\',\''+prefill_date[field_count]+'\')" '+free_attributes[field_count][0]+' /><input type="text" name="'+form_field_label+'_time" id="'+field_label[field_count]+'_time" size="6" readonly="true" value="'+prefill_time[field_count]+'" onclick="form_calendar(\''+field_label[field_count]+'_date\',\''+field_label[field_count]+'_time\',\'calendar'+calendar_count+'\',\''+prefill_date[field_count]+'\')" '+free_attributes[field_count][1]+' /><input type="button" value="[+]" onclick="form_calendar(\''+field_label[field_count]+'_date\',\''+field_label[field_count]+'_time\',\'calendar'+calendar_count+'\',\''+prefill_date[field_count]+'\')" /></td></tr></table><div id="calendar'+calendar_count+'"></div></td></tr></table>';
			calendar_count++;
		}
		// drop-down
		else if(field_type[field_count]==7){
			form_html=form_html+'<td valign="top"><b>'+field_label[field_count]+required_label+'</b><table><tr><td><select name="'+form_field_label+'" style="font-family:sans-serif;font-size:0.8em;" '+free_attributes[field_count][0]+'><option value="">- Please Select -</option><option value="">==================</option>';
			for(option_count=0;option_count<field_options[field_count].length;option_count++){
				if(prefill_value[field_count][option_count]){prefill_value[field_count][option_count]='selected="true"';}
				form_html=form_html+'<option value="'+field_options[field_count][option_count]+'" '+prefill_value[field_count][option_count]+' '+free_attributes[field_count][option_count+1]+' />&nbsp;'+field_options[field_count][option_count]+'</option>';
			}
			form_html=form_html+'</td></tr></table></td>';
		}
		// applicable
		else if(field_type[field_count]==8){
			form_html=form_html+'<td valign="top"><input type="hidden" name="'+form_field_label+'" value="-CHOICES BELOW-" /><b>'+field_label[field_count]+required_label+'</b><table style="font-family:sans-serif;font-size:1.0em;">';
			for(option_count=0;option_count<field_options[field_count].length;option_count++){
				if(prefill_value[field_count][option_count]){prefill_value[field_count][option_count]='checked="true"';}
				form_html=form_html+'<tr><td><input type="checkbox" name="'+field_options[field_count][option_count]+'" '+prefill_value[field_count][option_count]+' value="-YES-" '+free_attributes[field_count][option_count]+' /> </td><td>'+field_options[field_count][option_count]+'</td></tr>';
			}
			form_html=form_html+'</table></td>';
		}
		// hidden
		else if(field_type[field_count]==9){
			form_html=form_html+'<input type="hidden" name="'+form_field_label+'" value="'+return_value[field_count]+'" '+free_attributes[field_count][0]+' />';
		}
		// comment
		else if(field_type[field_count]==10){
			form_html=form_html+'</tr><tr><td valign="top" colspan="10" '+free_attributes[field_count][0]+'>'+field_label[field_count]+'</td></tr></table><table cellpadding="15" style="font-family:sans-serif;font-size:0.8em;"><tr>';
		}
		// e-mail
		else if(field_type[field_count]==11){
			form_html=form_html+'<td valign="top"><table style="font-family:sans-serif;font-size:1.0em;"><tr><td valign="top"><b>'+field_label[field_count]+required_label+'</b> </td><td valign="top"><input type="text" id="e_mail_field'+field_count+'" name="'+form_field_label+'" size="'+field_size[field_count]+'" onkeyup="javascript:if(this.value){if(!((this.value.indexOf(\'@\')>1)&&(this.value.indexOf(\'.\')<this.value.length-2)&&(this.value.indexOf(\'@\')<this.value.indexOf(\'.\')))){document.getElementById(\'alert_msg'+field_count+'\').innerHTML=\'Currently invalid e-mail address\';document.getElementById(\''+submit_button_id+'\').disabled=true;}else{document.getElementById(\'alert_msg'+field_count+'\').innerHTML=\'\';if(this.value!=document.getElementById(\'e_mail_field_verify'+field_count+'\').value){document.getElementById(\'alert_msg_verify'+field_count+'\').innerHTML=\'Currently e-mail address verification not matching!\';document.getElementById(\''+submit_button_id+'\').disabled=true;}else{document.getElementById(\'alert_msg'+field_count+'\').innerHTML=\'\';document.getElementById(\'alert_msg_verify'+field_count+'\').innerHTML=\'\';document.getElementById(\''+submit_button_id+'\').disabled=false;}}}else{document.getElementById(\'alert_msg'+field_count+'\').innerHTML=\'\';document.getElementById(\'alert_msg_verify'+field_count+'\').innerHTML=\'\';document.getElementById(\''+submit_button_id+'\').disabled=false;}" '+free_attributes[field_count][0]+' /><div id="alert_msg'+field_count+'" style="color:#ff0000;font-size:0.8em;"></div></td></tr><tr><td valign="top"><b>'+field_label[field_count]+' (verify)'+required_label+'</b> </td><td valign="top"><input type="text" id="e_mail_field_verify'+field_count+'" name="dummyfield" size="'+field_size[field_count]+'" onkeyup="javascript:if(this.value!=document.getElementById(\'e_mail_field'+field_count+'\').value){document.getElementById(\'alert_msg_verify'+field_count+'\').innerHTML=\'Currently e-mail address verification not matching!\';document.getElementById(\''+submit_button_id+'\').disabled=true;}else{document.getElementById(\'alert_msg_verify'+field_count+'\').innerHTML=\'\';document.getElementById(\''+submit_button_id+'\').disabled=false;}" '+free_attributes[field_count][1]+' /><div id="alert_msg_verify'+field_count+'" style="color:#ff0000;font-size:0.8em;"></div></td></tr></table></td>';
		}
		// password
		else if(field_type[field_count]==12){
			form_html=form_html+'<td valign="top"><table style="font-family:sans-serif;font-size:1.0em;"><tr><td valign="top"><b>'+field_label[field_count]+required_label+'</b> </td><td valign="top"><input type="password" id="password_field'+field_count+'" name="'+form_field_label+'" size="'+field_size[field_count]+'" onkeyup="javascript:if(this.value){if(this.value!=document.getElementById(\'password_field_verify'+field_count+'\').value){document.getElementById(\'alert_msg_verify'+field_count+'\').innerHTML=\'Currently password verification not matching!\';document.getElementById(\''+submit_button_id+'\').disabled=true;}else{document.getElementById(\'alert_msg_verify'+field_count+'\').innerHTML=\'\';document.getElementById(\''+submit_button_id+'\').disabled=false;}}else{document.getElementById(\'alert_msg_verify'+field_count+'\').innerHTML=\'\';document.getElementById(\''+submit_button_id+'\').disabled=false;}" onblur="this.value=check_chars(this.value,\''+permitted_chars[field_count]+'\',\''+field_label[field_count]+'\');" '+free_attributes[field_count][0]+' /></td></tr><tr><td valign="top"><b>'+field_label[field_count]+' (verify)'+required_label+'</b> </td><td valign="top"><input type="password" id="password_field_verify'+field_count+'" name="dummyfield" size="'+field_size[field_count]+'" onkeyup="javascript:if(this.value!=document.getElementById(\'password_field'+field_count+'\').value){document.getElementById(\'alert_msg_verify'+field_count+'\').innerHTML=\'Currently password verification not matching!\';document.getElementById(\''+submit_button_id+'\').disabled=true;}else{document.getElementById(\'alert_msg_verify'+field_count+'\').innerHTML=\'\';document.getElementById(\''+submit_button_id+'\').disabled=false;}" onblur="this.value=check_chars(this.value,\''+permitted_chars[field_count]+'\',\''+field_label[field_count]+'\');" '+free_attributes[field_count][1]+' /><div id="alert_msg_verify'+field_count+'" style="color:#ff0000;font-size:0.8em;"></div></td></tr></table></td>';
		}
		// read_only
		else if(field_type[field_count]==13){
			form_html=form_html+'<td valign="top"><b>'+field_label[field_count]+required_label+'</b> <input type="text" name="'+form_field_label+'" size="'+field_size[field_count]+'" value="'+prefill_value[field_count][0]+'" onblur="this.value=check_chars(this.value,\''+permitted_chars[field_count]+'\',\''+field_label[field_count]+'\');" '+free_attributes[field_count][0]+' /></td>';
		}
		// file
		else if(field_type[field_count]==14){
			form_html=form_html+'<td valign="top"><b>'+field_label[field_count]+required_label+'</b> <input type="file" name="'+form_field_label+'" size="'+field_size[field_count]+'" value="'+prefill_value[field_count][0]+'" onblur="this.value=check_chars(this.value,\''+permitted_chars[field_count]+'\',\''+field_label[field_count]+'\');" '+free_attributes[field_count][0]+' /></td>';
			enctype='enctype="multipart/form-data"';
		}

		// --- LINEBREAK ---
		if(linebreak[field_count]){
			form_html=form_html+'</tr></table><table cellpadding="15" style="font-family:sans-serif;font-size:0.8em;"><tr>';
		}

	}
	// --- submit_button ---
	if(submit_button_active){
		submit_button_active='';
	}else{
		submit_button_active='disabled="true"';
	}
	form_html='<form '+enctype+' name="jsForm" method="post" onsubmit="return checkForm();"><table cellpadding="15" style="font-family:sans-serif;font-size:0.8em;"><tr>'+form_html+'</tr></table><table width="100%"><tr><td colspan="10"><div align="right"><input type="submit" id="'+submit_button_id+'" value="'+submitbutton_txt+'" '+submit_button_active+' />&nbsp;&nbsp;&nbsp;</div></td></tr></table></form>';
	document.getElementById('mainform').innerHTML=form_html;
}

// Calendar Implementation
// USAGE: form_calendar([Date-Field ID, (opt.)], [Time-Field ID, (opt.)], [Calendar-Display-Field ID (usually <div></div>)], [preset date, (opt.)])

function form_calendar(datefield_id,timefield_id,calendarfield_id,new_date){
	var content='<table style="background-color:#ffffff;border: 1px solid #000000;""><tr><td valign="top" style="border: 1px solid #000000;">';
	if(!new_date){
		var new_date='';
	}
	if(datefield_id){
		var sdt=new Date();
		o_month=sdt.getMonth();
		o_year=sdt.getFullYear();
		if(new_date.indexOf('/')>0){
			date_in=new_date.split('/');
			if((date_in[0]-1==o_month) && (date_in[2]==o_year)){
				cday=sdt.getDate();
			}else{
				cday='0';
			}
			sdt.setDate(1);
			sdt.setYear(date_in[2]);
			sdt.setMonth(date_in[0]-1);
		}else{
			cday=sdt.getDate();
		}
		sdt.setDate(1);
		wkday=sdt.getDay();
		var mnth_name=new Array('January','February','March','April','May','June','July','August','September','October','November','December');
		var mnth_days=new Array(31,28,31,30,31,30,31,31,30,31,30,31);
		cyear=sdt.getFullYear();
		cmonth=sdt.getMonth();
		if(!(cyear%4) && (cyear!=2000)){mnth_days[1]++;}
		if(cmonth<1){
			var prev_month=12;
			var prev_year=cyear-1;
		}else{
			var prev_month=cmonth;
			var prev_year=cyear;
		}
		if(cmonth>11){
			var next_month=1;
			var next_year=cyear+1;
		}else{
			var next_month=cmonth+2;
			var next_year=cyear;
		}
		var prev_date=prev_month+'/1/'+prev_year;
		var next_date=next_month+'/1/'+next_year;
		content=content+'<table width="125" cellpadding="0" cellspacing="3" border="0" style="font-family: \'lucida console\',\'Bitstream Vera Sans Mono\',monospaced;font-size:10px;">';
		content=content+'<tr><td style="cursor:pointer;" onclick="form_calendar(\''+datefield_id+'\',\''+timefield_id+'\',\''+calendarfield_id+'\',\''+prev_date+'\')">&lt;</td><td colspan="5" align="center">'+mnth_name[cmonth]+' '+cyear+'</td><td align="right" style="cursor:pointer;" onclick="form_calendar(\''+datefield_id+'\',\''+timefield_id+'\',\''+calendarfield_id+'\',\''+next_date+'\')">&gt;</td></tr>';
		content=content+'<tr><td style="color:#ff0000;">Su</td><td>Mo</td><td>Tu</td><td>We</td><td>Th</td><td>Fr</td><td>Sa</td></tr>';
		start=sdt.getDay();
		for(x=0;x<(mnth_days[cmonth]+wkday);x++){
			content=content+'<td align="right"';
			if(x>=wkday){
				content=content+' style="cursor:pointer;';
				if(!(x%7)){
					content=content+'color:#ff0000;';
				}
				if((x-wkday+1)==cday){
					content=content+'background-color:#cccccc;';
				}
				content=content+'" onClick="javascript:document.getElementById(\''+datefield_id+'\').value=\''+(cmonth+1)+'/'+(x-wkday+1)+'/'+cyear+'\'">'+(x-wkday+1)+'</td>';
				if(!((x+1)%7)){
					content=content+'</tr><tr>';
				}
			}else{
				content=content+'>';
			}
		}
		content=content+'</table>';
		document.getElementById(calendarfield_id).innerHTML=content;
	}
	content=content+'</td>';
	if(timefield_id){
		var apm = new Array('A.M.','P.M.');
		content=content+'<td valign="top" style="border: 1px solid #000000;"><table cellpadding="0" cellspacing="3" border="0" style="font-family: \'lucida console\',\'Bitstream Vera Sans Mono\',monospaced;font-size:10px;">';
		content=content+'<tr><td colspan="7" align="center">Time</td></tr>';
		start=sdt.getDay();
		for(x=0;x<24;x++){
			if(!x){
				y=12;
			}else{
				y=x
			}
			content=content+'<td width="12" align="right" style="cursor:pointer;';
			if((x<6)||(x>17)){
				content=content+'background-color:#cccccc;';
			}
			content=content+'" onClick="javascript:document.getElementById(\''+timefield_id+'\').value=\''+(y-13*Math.floor(x/13)+Math.floor(x/13))+':00 '+apm[Math.floor(x/12)]+'\'">'+(y-13*Math.floor(x/13)+Math.floor(x/13))+'</td>';
			if(!((x+1)%6)){
				if(x==5){
					content=content+'<td style="cursor:not-allowed;border-left: 1px solid #000000;" rowspan="2">'+apm[0]+'</td>';
				}else if(x==23){
					content=content+'</tr><tr><td colspan="7"><hr /></td>';
				}else if(x==17){
					content=content+'<td style="cursor:not-allowed;border-left: 1px solid #000000;" rowspan="2">'+apm[1]+'</td>';
				}
				content=content+'</tr><tr>';
			}
		}
		content=content+'<td align="center" colspan="2" style="border: 1px solid #000000;cursor:pointer;" onclick="javascript:var s=document.getElementById(\''+timefield_id+'\').value;if(s.length){var n=s.substring(0,s.indexOf(\':\')+1)+\'00\'+s.substring(s.indexOf(\':\')+3); document.getElementById(\''+timefield_id+'\').value=n;}">:00</td><td align="center" colspan="2" style="border: 1px solid #000000;cursor:pointer;" onclick="javascript:var s=document.getElementById(\''+timefield_id+'\').value;if(s.length){var n=s.substring(0,s.indexOf(\':\')+1)+\'15\'+s.substring(s.indexOf(\':\')+3); document.getElementById(\''+timefield_id+'\').value=n;}">:15</td><td align="center" colspan="2" style="border: 1px solid #000000;cursor:pointer;" onclick="javascript:var s=document.getElementById(\''+timefield_id+'\').value;if(s.length){var n=s.substring(0,s.indexOf(\':\')+1)+\'30\'+s.substring(s.indexOf(\':\')+3); document.getElementById(\''+timefield_id+'\').value=n;}">:30</td><td align="center" colspan="2" style="border: 1px solid #000000;cursor:pointer;" onclick="javascript:var s=document.getElementById(\''+timefield_id+'\').value; if(s.length){var n=s.substring(0,s.indexOf(\':\')+1)+\'45\'+s.substring(s.indexOf(\':\')+3); document.getElementById(\''+timefield_id+'\').value=n;}">:45</td></tr>';
		content=content+'</table></td>';
	}
	content=content+'</tr><tr><td colspan="2" align="center"><span style="font-family: \'lucida console\',\'Bitstream Vera Sans Mono\',monospaced;font-size:10px;cursor:pointer;" onclick="javascript:document.getElementById(\''+calendarfield_id+'\').innerHTML=\'\';">[close]</span></td></tr></table>';
	document.getElementById(calendarfield_id).innerHTML=content;
}
