
function uploadChange(name, type)
{
	//$('#' + name + '_container').hide();
	$('#' + name+'_upload').show();
	
	frames[name + '_iframe'].openUpload();
	//var iframe = $('#' + name + '_upload iframe').get(0);
	//.document.getElementById('SWFUpload_0BrowseBtn').onclick();
	//uploadFrame.getElementById('SWFUpload_0BrowseBtn').onclick();
	return false;
}

function uploadRemove(name, type)
{
	//alert(document.getElementById(name+'_preview').src);
  if(type == 'image')
  {
    $('#' + name + '_preview').src(baseDir+'img/placeholder.png');
  }
  if(type == 'file')
  {
    $('#' + name +'_fileIcon').src(baseDir + 'img/filetypes/none.gif');
    $('#' + name +'_filename').html('No file uploaded');
  }
	$('#' + name).val('');	
	
	return false;
}


$(document).ready(function(){
  $('iframe').attr('allowtransparency', 'true');
  var focus = $('.form_error').get(0);
  if(focus != undefined)
  { 
    focus.focus(); 
  }
})

$(document).ready(function(){
  $("tr:nth-child(odd)").addClass("odd");
  //$.datePicker.setDateFormat('ymd','-');
  //$('.dateSelector').datePicker({startDate:'05/03/2006'});
  
  
  $('.textile-editor textarea').each(function(){
    edToolbar(this.id, 'extended');
  });
  

  
  
});


function insertAtCursor(myField, myValue) {
  //IE support
  if (document.selection) {
    myField.focus();
    sel = document.selection.createRange();
    sel.text = myValue;
  }
  //MOZILLA/NETSCAPE support
  else if (myField.selectionStart || myField.selectionStart == '0') {
    var startPos = myField.selectionStart;
    var endPos = myField.selectionEnd;
    myField.value = myField.value.substring(0, startPos)
    + myValue
    + myField.value.substring(endPos, myField.value.length);
  } else {
    myField.value += myValue;
  }
  myField.focus();
  return false;
}

// New site builder stuff --

function clearSelection() 
{
	var sel;
	if(document.selection && document.selection.empty)
	{
		document.selection.empty();
	} 
	else if(window.getSelection)
	{
		sel = window.getSelection();
		if(sel && sel.removeAllRanges)
		{
			sel.removeAllRanges() ;
		}
	}
}	
	
	$(document).ready(function(){
		
		if(parent.SectionsEditor != null)
		{
			parent.SectionsEditor.selectPage(sectionId);
		}
		
		$('.editable-content .content').hover(function(){
			$(this).addClass('hovered');
		}, function(){
			$(this).removeClass('hovered');
		});
		
		$('.editable-content').dblclick(function(){
			clearSelection();
			
			$('div.editor .input', $(this)).css('fontWeight', $('.content', $(this)).css('fontWeight'));
			$('div.editor .input', $(this)).css('fontSize', $('.content', $(this)).css('fontSize'));			
			$('div.editor .input', $(this)).css('fontFamily', $('.content', $(this)).css('fontFamily'));					
			$('div.editor .input', $(this)).css('textAlign', $('.content', $(this)).css('textAlign'));	
			
			$('div.editor .textile-editor', $(this)).css('fontSize', $('.content', $(this)).css('fontSize'));		
			
			$('div.editor', $(this)).show();
			//alert($('div.editor .input').get(0));
			$('div.editor .input', $(this)).get(0).focus();
			$('.content', $(this)).hide();
			return false;
		});
		
		$('.editable-content .save-button').click(function(){
			var contentBlock = $('.content', $(this).parent().parent());
			//console.log(contentBlock);
			contentBlock.removeClass('hovered');	
			$.post(
				baseDir + 'sections/save_content', 
				{ 
					id: $(this).parent().parent().attr('id'), 
					content: $('.input', $(this).parent()).attr('value') 
				}, function(data){
					contentBlock.html(data);
					$('div.editor', contentBlock.parent().parent()).hide();
					$(contentBlock).show();					
				}
			)
			
			return false;
		});
	});

