function initShareForm() {
	$('.ajaxOutput').html('');
	$('.ajaxOutput').hide();
// prepare the form when the DOM is ready 
    var options = { 
        target:        '#FWindowcontent .share .ajaxOutput',	// target element(s) to be updated with server response 
        beforeSubmit:  shareValidate,  	// pre-submit callback 
        success:       shareShowResponse,  // post-submit callback 
        resetForm: false       // reset the form after successful submit 
        // other available options: 
        //url:       url         // override for form's 'action' attribute 
        //type:      type        // 'get' or 'post', override for form's 'method' attribute 
        //dataType:  null        // 'xml', 'script', or 'json' (expected server response type) 
        //clearForm: true        // clear all form fields after successful submit 
        //resetForm: true        // reset the form after successful submit 
 
        // $.ajax options can be used here too, for example: 
        //timeout:   3000 
    }; 

    // bind to the form's submit event 
    //$('#sharePost').ajaxForm(options);

    // bind to the form's submit event 
    $('#FWindowcontent .sharePost .send').click(function() { 
        // inside event callbacks 'this' is the DOM element so we first 
        // wrap it in a jQuery object and then invoke ajaxSubmit 
        $('#FWindowcontent .sharePost').ajaxSubmit(options); 
 
        // !!! Important !!! 
        // always return false to prevent standard browser submit and page navigation 
        return false; 
    }); 
    
    $('#FWindowcontent .share textarea').toggleVal();
    $('#FWindowcontent .share input[name=receiverEmail]').toggleVal();

} 


function initDiscussForm() {
	$('.ajaxOutput').html('');
	$('.ajaxOutput').hide();
    var options = { 
        target:        '#FWindowcontent .discussForm .ajaxOutput',	// target element(s) to be updated with server response 
        beforeSubmit:  discussValidate,  	// pre-submit callback 
        success:       discussShowResponse  // post-submit callback 
 
        // other available options: 
        //url:       url         // override for form's 'action' attribute 
        //type:      type        // 'get' or 'post', override for form's 'method' attribute 
        //dataType:  null        // 'xml', 'script', or 'json' (expected server response type) 
        //clearForm: true        // clear all form fields after successful submit 
        //resetForm: true        // reset the form after successful submit 
 
        // $.ajax options can be used here too, for example: 
        //timeout:   3000 
    }; 

    // bind to the form's submit event 
    //$('#sharePost').ajaxForm(options);
	if(isLoggedIn) { 
	    // bind to the form's submit event 
	    $('#FWindowcontent .discussPost .send').click(function() { 
	        // inside event callbacks 'this' is the DOM element so we first 
	        // wrap it in a jQuery object and then invoke ajaxSubmit 
	        $('#FWindowcontent .discussPost').ajaxSubmit(options); 
	 
	        // !!! Important !!! 
	        // always return false to prevent standard browser submit and page navigation 
	        return false; 
	    }); 
	}
    else {
	    $('.ajaxOutput').html('<div class="error">You must login to post comments.</div>');
	    $('.ajaxOutput').show();
    }

    
    $('#FWindowcontent .discussPost textarea').toggleVal();
    $('#FWindowcontent .discussPost input').toggleVal();
}
 
//pre-submit callback 
function discussValidate(formData, jqForm, options) { 
	$('#FWindowcontent .discussForm .ajaxOutput').hide();

	var form = jqForm[0]; 
	
	$(".error").hide();
	var hasError = false;
	
	var content = $(form.content);
	if(content.val() == '' || content.val() == 'comment text') {
		$('#FWindowcontent .discussForm .ajaxOutput').html('<div class="error">You forgot to enter the comment.</div>');
		hasError = true;
	}
	if(hasError) {
		$('#FWindowcontent .discussForm .ajaxOutput').show();
		return false;
	}
    return true; 
} 
 
// post-submit callback 
function discussShowResponse(responseText, statusText)  { 
	$('#FWindowcontent .discussForm .ajaxOutput').hide();
	 if(responseText == 'ok') {
			$('#FWindowcontent .infoBox .boxRightContent .discussForm').hide();
			$('#FWindowcontent .infoBox .boxRightContent .discuss').show();
			mapmanager.loadDiscussion($('#FWindowcontent input[name=item_id]').val());
	 }
	 else {
	    alert('status: ' + statusText + '\n\nresponseText: \n' + responseText + 
	        '\n\nThe output div should have already been updated with the responseText.');
	 }
}


//pre-submit callback 
function shareValidate(formData, jqForm, options) { 
	$('#FWindowcontent .share .ajaxOutput').html('<p>Sending comment.</p>');
	$('#FWindowcontent .share .ajaxOutput').show();
	 

	var form = jqForm[0]; 
	
	$(".error").hide();
	var hasError = false;
	var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
	
	var receiverEmail = $(form.receiverEmail);
	if(receiverEmail.val() == '' || receiverEmail.val() == 'comment text') {
		$('#FWindowcontent .share .ajaxOutput').html('<div class="error">You forgot to enter the email address to send to.</div>');
		hasError = true;
	} else if(!emailReg.test(receiverEmail.val())) {	
		$('#FWindowcontent .share .ajaxOutput').html('<div class="error">Enter a valid email address to send to.</div>');
		hasError = true;
	}
	
	var comment = $(form.comment);
	if(comment.val() == '' || comment.val() == 'comment text') {
		$('#FWindowcontent .share .ajaxOutput').html('<div class="error">You forgot to enter the message.</div>');
		hasError = true;
	}
	if(hasError) {
		$('#FWindowcontent .share .ajaxOutput').show();
		return false;
	}
    return true; 
} 
 
// post-submit callback 
function shareShowResponse(responseText, statusText)  { 
	$('#FWindowcontent .share .ajaxOutput').hide();
	 if(responseText == 'ok') {
		 $('#FWindowcontent .share textarea[name=comment]').val('');
		 $('#FWindowcontent .share input[name=receiverEmail]').val('');
		 
		 $('#FWindowcontent .share .ajaxOutput').html('<p>Message sent.</p>');
		 $('#FWindowcontent .share .ajaxOutput').show();
	 }
	 else {
	    alert('status: ' + statusText + '\n\nresponseText: \n' + responseText + 
	        '\n\nThe output div should have already been updated with the responseText.');
	 }
}