function editSummary() {
	openContactContentEditor('summary');
}

function editDescription() {
	openContactContentEditor('description');
}

function editAboutUs() {
	openContactContentEditor('aboutus');
}

function openContactContentEditor(field) {

	var vars = {};
	
	vars['action'] = 'getContactById';
	
	openModalWindow(500, 500);
	
	$.ajax({

        dataType: 'jsonp',
        url: '/contact_profile.php',
        data: vars,
        type: 'POST', 
        
        success: function(json) {
			
			if (json['error_code']) {
				
				if (json['error_code'] == 1) {
					$('#divMessageDialog').html('Your login session has been expired.\nPlease login again.');
				} else {
					$('#divMessageDialog').html(json['error_message']);
				}
				
				setTimeout("closeContactContentEditor(); window.location.reload();", 2000);
				return;				
			}
			
			setContactContentEditor(json, field);
        },
        
        error: function(XMLHttpRequest, textStatus, errorThrown) {
			alert('Error:' + textStatus);
        }
	});	
}

function setContactContentEditor(json, field) {
	
	var content = json[CONTENT_TYPES[field]['dbfield'].toUpperCase()];
	
	var html = '';
	
	html += '<div id="divContactContentEditor">'
	html += '<table width="500" border="0" cellspacing="2" cellpadding="0">';
	html += '<tr>';
	html += '<td align="center">' + CONTENT_TYPES[field]['label'] + '</td></tr>';
	html += '<tr>';
	html += '<td align="center"><textarea id="content" name="content" wrap="hard" style="width:460px;height:380px">' + content + '</textarea></td></tr>';
	html += '<tr>';
	html += '<td align="center">';
	html += '<input type="button" value="Submit" onclick="saveContactContent(\'' + field + '\');">&nbsp;&nbsp;';
	html += '<input type="button" value="Cancel" onclick="closeContactContentEditor();">';
	html += '</table></div>';
	
	flipModalContent();
	
	$('#divModalContent').html(html);
		
	$('#divContactContentEditor #content').htmlarea({
		toolbar: [
	        ["html", "|", "increasefontsize", "decreasefontsize", "|", "bold", "italic", "underline", "|", "forecolor", "|", "indent", "outdent", "|", "orderedlist", "unorderedlist", "|", "justifyleft", "justifycenter", "justifyright", "|", "link", "unlink", "|", "image"]
		],
		css: '/library/css/jHtmlEditor.css'
	});
}

function saveContactContent(field) {
	
	var vars = {};
	
	vars['action'] 	= 'updateContactContent';
	vars['field'] 	= CONTENT_TYPES[field]['dbfield'];
	vars['content']	= $('#divContactContentEditor #content').val();
	
	flipModalContent();
	
	$.ajax({
	
        dataType: 'jsonp',
        url: '/contact_profile.php',
        data: vars,
        type: 'POST', 
        
        success: function(json) {
			
			if (!isNaN(json['contactid'])) {
				$('#divMessageDialog').html(CONTENT_TYPES[field]['label'] + ' has been submitted.');
			} else {
				$('#divMessageDialog').html('Error:' + CONTENT_TYPES[field]['label'] + ' could not be submitted.');
			}
			
			setTimeout("closeContactContentEditor(); window.location.reload();", 2000);
        },
        
        error: function(XMLHttpRequest, textStatus, errorThrown) {
			alert('Error:' + textStatus);
        }
	});	
}

function openModalWindow(h, w) {
	
	var html = '';
	
	html += '<span id="divOpenModal">';
	html += '	<span id="divLoadModal" class="nyroModalLoad" style="display:block;">';
	html += '		<span id="divMessageDialog" style="position:absolute; width:100%; text-align:center; top:' + ((h/2)-60) + 'px; color:#D56400; font-site:12px; font-weight:bold"></span>';
	html += '	</span>';
	html += '	<span id="divModalContent" style="display:none;"></span>';
	html += '</span>';
	
	$.nmData(html, {
		closeOnClick:false,
		sizes: {
			minH:h,
			minW:w
		}
	});
}

function flipModalContent() {
	
	if ($('#divLoadModal').css('display') == 'none') {
		$('#divLoadModal').css('display', 'block');
		$('#divModalContent').css('display', 'none');
	} else {
		$('#divLoadModal').css('display', 'none');
		$('#divModalContent').css('display', 'block');
	}
}

function closeContactContentEditor() {
	$.nmTop().close();
}
