

//var jQuery = jQuery.noConflict();

jQuery(document).ready(init)


function init(){
    jQuery("span[class='blogLink']").click(function(e){
		   editDiv('publicBlogEntry/create?topic=' + jQuery(this).attr('name'),e.pageX,e.pageY);
	   }); 
	   
	   jQuery("#popupwindow").draggable();
	if(typeof adjustHeight == 'function') {
		adjustHeight();
	}
}

function showpopup(x,y){
	jQuery('#popupwindow').animate( {top:y+100, left:x+100 } , 1 );
	jQuery('#popupwindow').show(1000);
	jQuery('#userName').focus();
}



function hidepopup(){
	jQuery('#popupwindow').hide(1000);
	init();
}

function fillContent(response,successDiv) {
		jQuery('#contentCache').html(response);
		var errorDiv='#editDiv';
		jQuery(errorDiv).html('');
		
		if(jQuery('#errorCounter') != null && jQuery('#errorCounter').attr('value') > 0){
			jQuery(errorDiv).html(jQuery('#contentCache').html());
		} else {
			if(jQuery('#'+ successDiv))
				jQuery('#'+ successDiv).html(jQuery('#contentCache').html());

			hidepopup();
			
		}
		jQuery('#contentCache').html('');
		
		if(typeof adjustHeight == 'function') {
			adjustHeight();
		}
} 


function submitForm(formName,updateDiv){
	jQuery('#createButton').attr('disabled','disabled');
	var url = jQuery('#'+formName).attr('action');
	var params = jQuery('#'+formName).serialize();
	jQuery.post(url,params,function(data){fillContent(data,updateDiv)});
 }

function editDiv(url,x,y){
	jQuery.post(url, function(data){jQuery('#editDiv').html(data); showpopup(x,y);});
}

function updateBlog(div,url) { 
	jQuery.post(url, function(data){jQuery('#'+div).html(data); init(); });

}


